On this page

Related pages

Template Variables

SiteGUI uses Smarty template system (https://www.smarty.net), facilitating the separation of presentation (HTML/CSS) from application logic. In Smarty, variables are pretty much like PHP variables, that means you can reference array variables by their key like $array["key"] or by specifying the key after a dot "." symbol like $array.key. Variables in Smarty can be either displayed directly or used as arguments for functionsattributes and modifiers, inside conditional expressions, etc. To print a variable, simply enclose it in {} ( {$variable} ) so that it is the only thing contained between them. Template Designers should get familiar with Smarty template syntax by referring to the official Smarty Documentation.

Available Variables

In addition to Smarty default variables, a Page or App Record should have the following variables available

  • {$sitegui}: this is always set to 1
  • {$token}: CSRF token
  • {$site}:
    • {$site.id}: Site ID
    • {$site.name}: Site Name
    • {$site.url}: Site URL
    • {$site.template}: Site Template
    • {$site.status}: Site Status
    • {$site.owner}: Site Owner ID
    • {$site.logo}: Site Logo URL
    • {$site.language}: Site Language
    • {$site.locales}: Supported Languages
    • {$site.cdn}: CDN URL for accessing static files (template, JS, CSS, images)
    • {$site.account_url}: URL for the customer portal
  • {$template}: effective template, could be either {$site.template} or the default template
  • {$api}
    • {$api.status.result}: request status
    • {$api.app}: App settings (depending on each app)
    • {$api.subapp}: App's subapps (depending on each app)
    • {$api.collections}: an array of collections/categories this page belongs to
    • {$api.related}: an array of pages this page is related to
    • {$api.page}
      • {$api.page.id}: Page/record ID
      • {$api.page.type}: Page Type (Page, Product, Collection, App, Link etc)
      • {$api.page.subtype}: Page Subtype
      • {$api.page.name}: Page Name/Label
      • {$api.page.slug}: Page Slug/URI
      • {$api.page.title}: Page Title (HTML Title)
      • {$api.page.description}: Page short description (SEO description)
      • {$api.page.content}: Page content
      • {$api.page.image}: Page's featured image
      • {$api.page.creator}: Creator ID of the Page
      • {$api.page.created}, {$api.page.updated}: Created/updated timestamp
      • {$api.page.published}: indicate the page is published if it is greater than 0, can be a timestamp to represent the date the page is/will be published
      • {$api.page.expire}: show when the page is no longer published
      • {$api.page.private}: if it is greater than 0, the page cannot be accessed by unauthenticated users, if it is a permission, the page can be accessed by users having the specified permission only
      • {$api.page.status}: Page Status
      • {$api.page.menu_id}: show which menu the page is a menu item
      • {$api.page.breadcrumb}: show/hide the navigation path for the page
      • {$api.page.layout}: custom layout for the page
      • {$api.page.views}: total view for the page
      • {$api.page.meta}: additional page's properties
      • {$api.page.public}: additional page's public properties (which can be changed by any user through automation)

    • {$html}
      • {$html.breadcrumbs}: an array of breadcrumbs items
      • {$html.top_menu}: an array of menu items for the top position 
      • {$html.bottom_menu}: an array of menu items for the bottom position 
      • etc
    • {$links}: an array of links to manipulate the page
    • {$block_xxx}: 'xxx' can be a position such as head, header, spotlight, top, bottom, left, right, main, footnote, footer, 1-15. These variables hold the generated output for each BlockHolder, as the generated outputs are already HTML escaped, these variables should be printed with nofilter attribute e.g: {$block_top nofilter}
    • {$xxx_menu}: 'xxx' is a position e.g: {$top_menu}. These variables contain an array of menu items, you can use {foreach} to display them.
    • other variables depending on each app

    Sample template variables and data

      Array
    (
        [sitegui] => 1
        [token] => 68a00a20a
        [site] => Array
            (
                [id] => 1000
                [name] => SiteGUI
                [url] => sitegui.com
                [tier] => 1
                [server] => 
                [template] => 
                [status] => Active
                [owner] => 123456
                [revision] => 1
                [version] => 1
                [auto_upgrade] => 1
                [language] => en
                [timezone] => America/New_York
                [editor] => wysiwyg
                [logo] => https://cdn.sitegui.com/bootstrap5/assets/img/logo.png
                [locales] => Array
                    (
                        [en] => english
                    )
                [cdn] => https://cdn.sitegui.com/public/templates/global
                [account_url] => https://my.sitegui.com/account
            )
        [template] => lumen
        [api] => Array
            (
                [status] => Array
                    (
                        [result] => success
                    )
                [page] => Array
                    (
                        [id] => 398
                        [type] => App
                        [subtype] => Feature_Request
                        [name] => Add New Entry button for public app page
                        [slug] => /feature_request/add-new-entry-button-for-public-app-page
                        [title] => Add New Entry button for public app page
                        [description] => 
                        [content] => There is no button to create a new entry when viewing an app. Please add it.
                        [image] => 
                        [creator] => 123456
                        [created] => 1676311649
                        [updated] => 1676342248
                        [published] => 1676342248
                        [expire] => 0
                        [private] => 
                        [status] => Backlog
                        [menu_id] => 
                        [breadcrumb] => 1
                        [layout] => 
                        [views] => 0
                        [meta] => Array
                            (
                                [category] => Array
                                    (
                                        [0] => Improvement
                                    )
                            )
                        [public] => Array
                            (
                                [rating] => 4.5
                                [count] => 11
                            )
                    )
                [app] => Array
                    (
                        [sub] => Array
                            (
                                [Comment] => Array
                                    (
                                        [entry] => multiple
                                        [display] => flat
                                    )
                                [Like] => Array
                                    (
                                        [entry] => single
                                        [display] => grid
                                    )
                            )
                    )
                [subapp] => Array
                    (
                        [Comment] => Array
                            (
                                [show] => Array
                                    (
                                        [content] => Array
                                            (
                                                [type] => textarea
                                                [label] => Content
                                                [visibility] => client_editable
                                            )
                                    )
                                [fields] => Array
                                    (
                                        [attachment] => Array
                                            (
                                                [type] => file
                                                [label] => Attachment
                                                [visibility] => client_editable
                                                [column] => 1
                                                [is] => multiple
                                            )
                                    )
                            )
                        [Like] => Array
                            (
                                [fields] => Array
                                    (
                                        [name] => Array
                                            (
                                                [type] => radio hover
                                                [label] => Feeling
                                                [is] => optional
                                                [visibility] => client_editable
                                                [options] => Array
                                                    (
                                                        [👍] => 👍
                                                        [🤔] => 🤔
                                                    )
                                            )
                                        [status] => Array
                                            (
                                                [type] => rating
                                                [label] => Rating
                                                [is] => optional
                                                [visibility] => client_editable
                                                [column] => 1
                                            )
                                    )
                            )
                    )
                [collections] => Array
                    (
                        [0] => Array
                            (
                                [id] => 549
                                [type] => Collection
                                [subtype] => App::Feature_Request
                                [slug] => /feature_request/category/improvement
                                [name] => Improvement
                            )
                    )
                [related] => Array
                    (
                        [0] => Array
                            (
                                [id] => 2448
                                [type] => App
                                [subtype] => Feature_Request
                                [slug] => /feature_request/hide-the-sample-code
                                [name] => Hide the sample code
                                [description] => 
                                [image] => 
                            )
                        [1] => Array
                            (
                                [id] => 3396
                                [type] => App
                                [subtype] => Feature_Request
                                [slug] => /feature_request/add-supervisor-as-a-special-value-for-poster-in-app-builders-actions
                                [name] => Add {{supervisor}} as a special value for {{poster}} in App Builder's Actions
                                [description] => 
                                [image] => 
                            )
                    )
            )
        [links] => Array
                    (
                        [subapp] => /feature_request/add-new-entry-button-for-public-app-page
                        [file_view] => /file/view
                        [update] => https://my.sitegui.com/account/app/update
                    )
    
    
        [html] => Array
            (
                [ajax] => 1
                [breadcrumbs] => Array
                    (
                        [0] => Array
                            (
                                [name] => Feature Request
                                [slug] => /feature_request/
                            )
                        [1] => Array
                            (
                                [name] => Frontend
                                [slug] => /feature_request/category/frontend
                            )
                        [2] => Array
                            (
                                [name] => Styling
                                [slug] => /feature_request/category/styling
                            )
                    )
                [top_menu] => Array
                    (
                        [0] => Array
                            (
                                [id] => 1
                                [type] => Page
                                [subtype] => 
                                [name] => Home
                                [slug] => /index.html
                            )
                        [1] => Array
                            (
                                [id] => 5
                                [type] => Page
                                [subtype] => 
                                [name] => Support
                                [slug] => #
                                [children] => Array
                                    (
                                        [4] => Array
                                            (
                                                [id] => 4
                                                [type] => Link
                                                [subtype] => 
                                                [name] => Tickets
                                                [slug] => https://my.sitegui.com/account/app/ticket
                                            )
    
                                        [3] => Array
                                            (
                                                [id] => 3
                                                [type] => Link
                                                [subtype] => 
                                                [name] => Open Ticket
                                                [slug] => https://my.sitegui.com/account/app/view/ticket
                                            )
                                    )
                            )
                    )
    
                [footer_menu] => Array
                    (
                        [0] => Array
                            (
                                [id] => 5
                                [type] => Page
                                [subtype] => 
                                [name] => Support
                                [slug] => #
                                [children] => Array
                                    (
                                        [4] => Array
                                            (
                                                [id] => 4
                                                [type] => Link
                                                [subtype] => 
                                                [name] => Tickets
                                                [slug] => https://my.sitegui.com/account/app/ticket
                                            )
                                        [3] => Array
                                            (
                                                [id] => 3
                                                [type] => Link
                                                [subtype] => 
                                                [name] => Open Ticket
                                                [slug] => https://my.sitegui.com/account/app/view/ticket
                                            )
                                    )
                            )
                        [1] => Array
                            (
                                [id] => 7
                                [type] => Page
                                [subtype] => 
                                [name] => Company
                                [slug] => #
                                [children] => Array
                                    (
                                        [6] => Array
                                            (
                                                [id] => 6
                                                [type] => Page
                                                [subtype] => 
                                                [name] => Contact Us
                                                [slug] => /contact
                                            )
                                        [8] => Array
                                            (
                                                [id] => 8
                                                [type] => Page
                                                [subtype] => 
                                                [name] => Terms of Service
                                                [slug] => /tos
                                            )
                                    )
                            )
                    )
            )  
    

    Common Smarty functions and modifiers

    • {include 'header.tpl'}:  used for including other templates in the current template
    • {extends 'header.tpl'}:  used in child templates for extending parent templates
    • {assign var='name' value='any'} or {$name = 'any'}: used for assigning template variables during the execution of a template
    • {literal}{/literal}: used to escape Smarty interpreter, anything between {literal} and {/literal} is not interpreted and displayed as-is
    • {if $name eq 'Fred'} Welcome Sir. {elseif $name eq 'Wilma'} Welcome Ma'am. {else} Welcome, whatever you are. {/if}
    • {foreach $var as $key => $item} {$key}: {$item|escape} {/foreach}
    • {$myVar|trans}: translate the variable to site's current language
    • {["There is :qty :fruit", "There are :qty :fruits"]|trans:["qty"=> $qty, "fruit" => "apple"]:$qty}: translate using placeholders and different string selection by providing placeholder replacements and quantity as the first and second param to the modifier trans
    • {$myVar|capitalize}: capitalize the first letter of all words in a variable
    • {$myVar|lower}: convert variable's value to lowercase
    • {$myVar|replace:'foo':'bar'}: replace 'foo' with 'bar'
    • {$myVar|default:'anything'}: if the variable is empty, use the specified default value instead
    • {$myVar|escape}: HTML encode the variable
    • {$myVar nofilter}: do not escape the variable even if $escape_html is set to true