0

Twig templates - Page template functions {{ fn.* }}

The following custom Twig functions can be used within page templates (Themes > Templates):

navigation(attributes_json)

Outputs navigation menus.

{{ fn.navigation({"group":"Primary navigation","levels":1,"template":"Primary navigation"}) }}


The attributes JSON string accepts the following properties:

  1. page_id - Integer - The child pages of the specified page's ID will be output as the top level of the navigation.
  2. group - String - Use in place of page_id to display the pages of one of the site tree's page groups (e.g. "Primary navigation").
  3. template - Integer | String - The ID or title of the content template (Themes > Content templates) to use to output the navigation's HTML.
  4. use_siblings - Boolean - If a page_id is specified, use_siblings will set the navigation to use the specified page and it's siblings as the top level of the navigation, instead of the page's children.
  5. levels - Integer - Default: 0 - The number of levels deep in the page heirarchy to output. For example, a setting of 1 will output the root level and one level deep, useful for drop down menus. 


redirect(status_code = 404, url) 

Allows the template to force a header redirect to another URL before the page has completed processing.

{{ fn.redirect(301, 'http://example.com') }}


template(template)

Outputs the content of another template.

Example: {{ fn.template('Document head') }} 


css_min(titles_and_urls) 

Creates a minified file of a collection of CSS files, uploads the file to a CDN and outputs the file's src.

<link rel="stylesheet" href="{{ fn.css_min(['Base','http://assets.omcore.net/libs/cookie-use/1.0.0/cookie-use.css']) }}">


The titles_and_urls array can consist of any combination of the following:

  1. A title of a CSS item from Themes > CSS e.g. "Base".
  2. The absolute URL of a remote CSS file.


js(titles_and_urls)

Creates a minified file of a collection of JavaScript files, uploads the file to a CDN and outputs the file's src.

<script src="{{ fn.js(['http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js','Script']) }}"></script>


The titles_and_urls array can consist of any combination of the following:

  1. A title of a JavaScript item from Themes > JavaScripts e.g. "Script".
  2. The absolute URL of a remote JavaScript file.


js_min(titles_and_urls)

<script src="{{ fn.js_min(['http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js','Script']) }}"></script>

 
Similar to js() above, except this function outputs the minified JavaScript, without creating a file.


content(attributes_json)

Outputs the processed HTML of any content type.

{{ fn.content('{"content_id":123}') }} 
{{ fn.content('{"page_id":234,"area":"Right sidebar"}') }}


The attributes JSON string accepts the following properties:

  1. content_id - Outputs the content specified by the ID
  2. page_id - Must be used in combination with the area attribute. Outputs the content of a specific page's content area.
  3. area - The name of a content area e.g. "Right sidebar".

This function can also be used in page templates (Themes > Templates).


img(title)

Outputs the src of an image from the Themes > Images component.

{{ fn.img('Logo') }}


This function can also be used in page templates (Themes > Templates).

 

0 comments

Please sign in to leave a comment.