Variables

Global variables

In every template or component there's a number of variables that are always available.

Asset directory paths

To generate absolute URI-s to asset directories (such as directories for images or stylesheets), there are number of convenience variables to generate paths to these directories. 44 Gallons Web has the following conventions to store external files on site:

  • Images to be used in page layouts are stored in /images directory. There is a {{ images_path }} variable to generate URI to images directory.
  • Javascript files are stored inside /javascripts directory. Use {{ javascripts_path }} to generate URI.
  • Stylesheet files are stored inside /stylesheets directory. Use {{ stylesheets_path }} to generate URI.
  • Photos uploaded by user are stored inside /photos directory. Use {{ photos_path }} to generate URI.
  • All other files except photos are stored inside /files directory. Use {{ files_path }} to generate URI.
  • Absolute URI to site root can be generated with {{ site_path }} variable.
Example of creating path to image:

 <img src="{{ images_path }}/background.png" border="0" />

Notice that you have to add trailing slash after variable.

Determining if CMS session is active

If your layout code needs to make some decisions based whether user has been logged into CMS or not, you can use editmode variable which returns true when logged in. This variable can be used in conunction with if or unless tags. Editmode has some common usage scenarios:

  • Not generating HTML code for statistics engines, such as Google Analytics, in CMS editors to generate false statistics.
  • Not generating code for UI-candy bloat in public site, for example, Flash movies.
  • Generating in-page widgets to make editing page easier.
Example of not generating code for Google Analytics in editing mode:

 {% unless editmode %}{{ site.analytics }}{% endunless %}

Custom variables

You can create your own variables to be used in templates by using the assign tag.