Global Variables

There are two primary global variables injected into your templates.

The entry global#

The entry global variable is injected into your templates whenever a request to Enact matched a entries URL (this global will not exist if the the request was not matched directly to an entry, see the Routing Docs for other ways requests are resolved). The entry global is an instance of an Entry Wrapper. It provides the properties of the matched entry, access to the fields used by the entry accessed directly by the fields handles, and helper methods which allow for printing and searching. See the Entry Wrapper docs for full information for using the entryglobal.

The enact global#

The enact global encapsulates functionality and access to services and variables provided by enact. The methods provided by it are wide ranging, below we will detail them.

enact.siteName

Get the site name as defined in the general settings.

<h1>Welcome to {{ enact.siteName }}, enjoy your visit!</h1>
enact.siteLogo

Get the site logo as defined in the general settings.

{{ enact.siteLogo }}
enact.siteIcon

Get the site icon (favicon) as defined in the general settings.

{{ enact.view.favIcon( enact.siteIcon.url ) }}
enact.globals

Access the global fields established in the globals tab of Enact.

<div>Call us at {{ enact.globals.phoneNumber }}</div>
enact.siteUrl

Get the FQDN of the site.

<a href='{{ enact.siteUrl }}/about-us'>About {{ enact.siteName }}</a>
enact.loginUrl

Get the URL that users login to Enact at.

<a href='{{ enact.loginUrl }}'>Login</a>
eanct.logoutUrl

Get the URL that users logout of Enact at.

<a href='{{ enact.logoutUrl }}'>Logout</a>
enact.currentUser

Get the currently logged in user, if no user the returned value is null, otherwise returns a User Wrapper.

{% if enact.currentUser %}

    <div>{{ enact.currentUser.displayName }}</div>

    {{ enact.currentUser.getImgHtml }}

{% endif %}
enact.config

Get a current configuration settings

{% if enact.config('devMode') %}

// running in dev mode

{% endif %}
enact.now

Get a PHP DateTime object set to the current time.

<div>Current UNIX : {{ enact.now.getTimestamp }}</div>
enact.quit

Force the request to exit, literally calling exit in PHP.

{{ enact.quit }}
enact.dd

Perform a “dump and die” on a variable. Use this for inspecting things.

{{ enact.dd( entry ) }}
enact.plugin

Get a plugins template class.

{% set SomePlug = enact.plugin.PluginName %}

{{ SomePlug.method }}
enact.csrfTokenValue

Get the value of the current users CSRF token.

CSRF value : {{ enact.csrfTokenValue }}
enact.csrfTokenName

Get the name of the current users CSRF token.

CSRF name : {{ enact.csrfTokenName }}
enact.csrfTokenInput

Get a hidden input for use in forms that provides the CSRF token name/value.

{{ enact.csrfTokenInput }}

{#

which is equivalent to performing
<input type='hidden' name='{{ enact.csrfTokenName }}' value='{{ enact.csrfTokenValue }}'/>

#}
enact.rss

Fetch a RSS feed.

enact.rss('url', limit, offset, cacheDuration)

Arguments:

  • url (string) - The url to the RSS feed.

  • limit (null | integer) - The maximum number of items returned in the feed, if not provided or null, the entire feed will be returned.

  • offset (null | integer) - The offset of the items to return, if not provided or null, items starting from 0 index will be returned.

  • cacheDuration (null | integer | string) – The amount of time to cache the request for, if not provided or null, the feed will be cached for the amount of time defined by the configuration setting cacheDuration. If you provide an integer it will be cached for that number of seconds. You can also provide a string like +30 minutes, +1 hour, +1 day.

{% set feed = enact.rss('https://news.ycombinator.com/rss') %}

<h1>{{ feed.title }}</h1>

<a href='{{ feed.link }}'>{{ feed.description }}</a>

{% for item in feed.item %}

    <a href='{{ item.link }}'>{{ item.title }} - {{ item.pubDate }}</a>

{% endfor %}

Sub Services#

enact.view

Access the current view class, which provides tons of helper methods for building your templates.

See View Docs.

enact.request

Access the request class, which provides information about the current request.

See Request Docs.

enact.session

Access the session class, which provides information on the current session.

See Session Docs.

enact.cache

Access the cache class, which provides the ability to manage cached data.

See Cache Docs.