Involver Developer Network : Chapter 1 - Hello World!
This page last changed on Sep 14, 2011 by kristin.bradley@involver.com.
This chapter is a step-by-step guide on setting up your first SML application, Hello World! The walkthrough assumes you have basic web development knowledge (HTML/CSS) and experience with Facebook Fan Pages. After completing this chapter you'll be familiar with installing, configuring and previewing SML applications as well as introduced to key building blocks in the language - tags, variables & filters. Installation
Configuration
Adding StylingCongratulations, you've written your very first SML application! Unfortunately, it's rather bland looking. Let's change that by addding some styling...
Adding Images
<style> h2 { font-family: Arial, Helvetica; font-size: 40px; } </style> <h2>Hello World!</h2> <img src="http://involver.com/img/involver.png" alt="">
Making the image more maintainable with the editable_image tagOur application now shows an image - but we've now added a dependency to an externally hosted asset. If the external location were to change, our image would break. Also changing the image requires direct modification of the SML template. Wouldn't it be great if we could specify a hosted, editable image that is separated from the template? We can do exactly that with the editable_image SML tag...
<style> h2 { font-family: Arial, Helvetica; font-size: 40px } </style> <h2>Hello World!</h2> {% editable_image name: "logo" %}
To show just the url of the image and not the image itself (useful for creating a link or lightbox-style popup to a big image from a small one or for inserting an image path into your CSS so you can set it as the background of a div) you would add the attribute "src_only" and the value "true" to your tag like so: {% editable_image name:"name_of_your_image" src_only:true %}
A brief introduction to SML tags{% editable_image %} is an example of an SML tag. SML tags are surrounded by {% %}. There are many tags at your disposal - some are used for logic and control flow i.e. {% if %} and {% for %}, while others like {% editable_image %} provide powerful abstractions you can leverage in your applications to streamline development and maintenance. You can think of SML tags like self-closing HTML tags - they have a name and zero or more attributes - but their power extends far beyond laying out page elements. There are two types of markup in SML: Output and Tag.Output markup (which may resolve to text) is surrounded by {{ matched pairs of curly brackets (ie, braces) }} Tag markup (which cannot resolve to text) is surrounded by {% matched pairs of curly brackets and percent signs %} Output Markup can be formated and have the text it outputs modified by using Filters (more on those in a moment) while Tag Markup is used to insert and format powerful SML applications, editable objects, and more. Lets start out with a simple Output Markup tag and get some practice there before moving on to more complex examples. Showing today's date with the now variableLike any modern language, SML allows developers to assign and reference variables. Some variables are automatically assigned for you. These pre-created variables are called context variables. Let's output the current date along with our message and logo. We can do this using the {{ now }} global context variable. now is an example of a Global Context Variable in SML. These are special Output Markup variables that have a global scope, meaning they can be used anywhere in your template.
<style> h2 { font-family: Arial, Helvetica; font-size: 40px } </style> <h2>Hello World!</h2> <p>{% editable_image name: "logo" %}</p> <p>Today is: {{ now }}<p>
Formatting today's date with the date filterOur application displays the current date, but the format shown is not very user friendly. Let's change the format to mm/dd/yy. We'll do this by using an SML Filter called date. Filters are simple utility functions that operate on variables, transforming them to some new output. They are separated by the pipe (|) character and can take arguments. They can also be chained together.
Filters are an important part of the language so it's important to get an understanding of their utility. Many filters are used for formatting (as with date) while others perform arithmetic and some can even rewrite HTML markup. Next StepsBy now you should have a foundational understanding of the SML development workflow. You should also have a basic conceptual grasp of tags, global context variables and filters. See the links below which serve as references for the SML tag, global context variables and filter libraries. Try experimenting with simple tags and filters in your Hello World application. On to Chapter 2![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
Document generated by Confluence on Feb 12, 2013 09:09 |