Template coding style guide


Introduction

The template coding style guide provides information on how to use template tags and variables in the Outlast Framework template language. All HTML and Javascript code must follow the style guides for their respective languages.

Inline styling and Javascript

Inline styles and inline javascript are generally forbidden unless absolutely necessary. Inline styling can be used when you have dynamic background images for example or in email templates where it is necessary. You should generally use data-attributes if you need to pass data Javascript.

Spacing for tags, filters, and variables

Tag names will have spaces around them {% foreach %} while variables will not {{variable}}. There are also no spaces when filtering variables such as {{variable|truncate:30}}.

Language and config variables are the same as in {{#variable#}}.

Cases for tags, filters, and variables

All tags and all variables are lower case. If you have multiple words in tag names or variables, use underscores for spacing as in {{this_is_a_long_variable_name}}. The same holds true for filters and variables, although these will many times follow the way it is originally done in PHP, which is often inconsistent.

Language and config variables are the same as in {{#this_is_a_long_lang_var#}}.

When to use quotes and when not to

You are limited to a few expressions in variables and tag parameters. You can use booleans, variables, config/lang variables, strings, or numeric values.

Quotes are not required for the two boolean expressions true / false and for integers and floats 24.3. Any other string without quotes will be considered a variable. Strings should be used with single quotes.

Here are some examples:

{{'fixed string'}}
{{variable}}
{% if true %}
{{number|add:2}}
{{3|add:3}}
{{#lang_variable#|printf:'fixed string'}}

File naming conventions

Most of the time, your templates will generate html, but this file extension is not required. If you are generating XML, SQL, or any other format with the template system, you should use the relevant extensions for the file name.

Like with variable names, file names should be lower_case_seperated_with_underscore.html.

View files should typically go under subfolders named after the controllers that call them. So if you have a profile.ctl.php controller that lists a profile edit page, then you should have a /app/view/profile/edit.html or optionally /app/view/profile/profile_edit.html. The latter is more wordy, but helps you use “quick open” features more easily when you have projects with lots of similarly named files (for example edit.html-s in many, many different subfolders).

Files that are not full templates but are meant to be {% insert %}-ed from other templates (usually known as partials) should use an underscore in front of their names such as _news_item.html.

Admin interfaces should follow the folder structure and file naming found in the admin template or whatever is generated using the admin generator script.

Outlast Web & Mobile Development (c) 2018 | Privacy Policy |