CMS Ametys provides integrators with numerous Twig functions that can be used directly in templates, facilitating the integration of graphic charters.
Description:
Returns the application context according to the rendering context, e.g. '/cms', '/cms/preview'.
This function can be used to access the server via AJAX requests.
The result may be empty if the application context corresponds to the domain root.
Signature :
String uriPrefix()
Example:
$j.post("{{ uriPrefix() }}"/>/plugins/cms/comments/add-comment", data, result);
Description:
Identical to uriPrefix but adding the protocol and server name to obtain an aboslue address, for example'http://www.ametys.org' or'http://www.ametys.org/cms' or'http://www.ametys.org/cms/preview'.
Signature :
String absoluteUriPrefix()
Description:
Returns the site context specified in the parameter (current site if no parameter) according to the rendering context, e.g. '/cms/www', '/cms/preview/www'.
This function can be used to build a path to a page.
The result may be empty if the site context corresponds to the domain root.
Signature:
String siteUriPrefix()
String siteUriPrefix(String siteName)
Arguments:
Name | Type | Description |
---|---|---|
siteName | String | Site name |
Example:
<a href="{{ siteUriPrefix() }}/{{ lang() }}/index.html">Accueil</a> <a href="{{ siteUriPrefix('www') }}/{{ lang() }}/index.html">Accueil</a>
Description:
Same as siteUriPrefix but returns an absolute value, for example'http://www.ametys.org' or'http://www.ametys.org/cms/www' or'http://www.ametys.org/cms/preview/www'.
Useful for obtaining the site'sURL (to create the "I like facebook" button, for example).
Signature:
String absoluteUriPrefix()
String absoluteUriPrefix(String siteName)
Arguments:
Name | Type | Description |
---|---|---|
siteName | String | Site name |
Description :
Returns the name of the graphic charter used by the current site.
Signature :
String skin()
Description:
Returns the path to the graphic charter resource file.
Signature:
String skinURL(String path)
Arguments:
Name | Type | Description |
---|---|---|
path | String | Path to a graphic charter resource |
Example:
Insert an image located in the cms/skins/[skinName]/resources/img/[imageName].png directory.
<img src="{{ skinURL('img/[imageName].png') }}"/>
Description:
Returns a DOM node representing the sub-directory of the resources directory of the graphic charter currently in use.
This makes it possible, for example, to create a slideshow of all the images in a directory without knowing the names of all the files.
See resourcesById for the DOM description.
Signature :
Collection skinResources(String path)
Arguments:
Name | Type | Description |
---|---|---|
path | String | Path in the resources directory of the graphic charter |
Example:
<ul> {% for resource in skinResources('img/slideshow') %} <img src="{{ skinURL('img/slideshow/' ~ resource.name)) }}"/> {% endfor %} </ul>
Description:
Returns a graphic image encoded in base 64. The image is then integrated directly into the page body HTML .
Signature:
String skinImageBase64(String path)
Arguments:
Name | Type | Description |
---|---|---|
path | String | Image path in graphic resources directory |
Example:
<img src="{{ skinImageBase64('img/header.jpg') }}" />
Description:
Returns the name of the template currently in use.
Signature :
String template()
Description:
Returns the path to the argument resource contained in the current graphic template.
Signature:
String templateURL(String path)
Arguments:
Name | Type | Description |
---|---|---|
path | String | Path to a graphic template resource |
Example:
Insert an image located in the directory cms/skins/[skinName]/templates/[currentTemplateName]/resources/img/[imageName].png".
<img src="{{ templateURL('img/[imageName].png') }}"/>
Description:
Returns the name of the zone currently in use. Useful for content or service rendering.
Note that content rendering can also be viewed outside a page with no associated zone, so a default value must be passed as a parameter.
Signature :
String zone (String defaultValue)
Arguments:
Name | Type | Description |
---|---|---|
defaultValue | String | Default value if no zone is in use |
Example:
{% set zone = zone("default") %} {% if zone == 'default' %} <!-- Nous sommes dans la zone 'default' --> ... {% elseif zone == 'right' %} <!-- Nous sommes dans la zone 'right' --> ... {% else %} <!-- Nous sommes dans la zone 'left' --> ... {% endif %}
Description:
Returns the identifier of the site containing the current page.
Signature :
String site()
String site(String pageId)
Arguments:
No
Name | Type | Description |
---|---|---|
pageId | String | Unique page identifier |
Description:
Returns the language code of the current page.
Signature :
String lang()
String lang(String pageId)
Arguments:
No
Name | Type | Description |
---|---|---|
pageId | String | Unique page identifier |
Example:
<a href="{{ siteUriPrefix() }}/{{ lang() }}/index.html">Accueil</a>
Description:
Returns the path to the current page. This path is relative to the site map.
Signature :
String pagePath()
Description:
Returns the unique identifier of the current page (in the form page://...).
Signature :
String pageId()
Description:
Returns the page title.
Signature:
String pageTitle(String sitename, String lang, String path)
String pageTitle(String pageId)
Arguments:
Name | Type | Description |
---|---|---|
sitename | String | Site identifier |
lang | String | Site language code |
path | String | Page path in sitemap |
Name | Type | Description |
---|---|---|
pageId | String | Unique page identifier |
Example:
This will return the title of the home page: "Home" or "Accueil".
{{ pageTitle(site(), lang(), 'index') }}
Description:
Identical to pageTitle except that it returns the long title.
Note that if there is no long title, the title is returned.
Signature:
String longPageTitle(String sitename, String lang, String path)
String longPageTitle(String pageId)
Arguments:
Name | Type | Description |
---|---|---|
sitename | String | Site identifier |
lang | String | Site language code |
path | String | Page path in sitemap |
Name | Type | Description |
---|---|---|
pageId | String | Unique page identifier |
Description:
Returns the value of a page metadata as a character string.
Signature:
String pageMetadata (String sitename, String lang, String path, String metadataName)
String pageMetadata (String pageId, String metadataName)
Arguments:
Name | Type | Description |
---|---|---|
sitename | String | Site identifier |
lang | String | Site language code |
path | String | Page path in sitemap |
metadateName | String | Metadata name. Use the '/' character to access composite metadata. |
Name | Type | Description |
---|---|---|
pageId | String | Unique page identifier |
metadataName | String | Metadata name. Use the '/' character to access composite metadata. |
Description:
Returns the status of the page according to whether it is restricted or not: false if the page is public, otherwise true.
Signature :
boolean pageHasRestrictedAccess(String pageId)
Arguments:
Name | Type | Description |
---|---|---|
pageId | String | Unique page identifier |
Description:
Returns a list of pages corresponding to a search by tag, in the form :
Signature :
Collection findPagesIdsByTag(String tag)
Collection findPagesIdsByTag(String sitename, String lang, String tag)
Arguments:
Name | Type | Description |
---|---|---|
tag | String | Page label identifier |
Name | Type | Description |
---|---|---|
sitename | String | Site name. For example 'www'. |
lang | String | Language code. For example 'fr'. |
tag | String | Page label identifier. |
Example:
To create a list of links to pages bearing the TEST label.
{% set testPages = findPagesIdsByTag('TEST') %} {% if testPages is not null %} <ul> {% for page in testPages %} <li> <a href="{{ resolve('page', page.id) }}">{{ pageLongTitle(page.id) }}</a> </li> {% endfor %} </ul> {% endif %}
Description:
Determines whether the service, content or page you're on is cacheable, i.e. can be cached.
If isCacheable is called from a service rendering, the method returns the status of the service with respect to the cache.
If isCacheable is called from content rendering, the method returns the content's cache status.
If isCacheable is called at skin, the method returns the page's cache status.
Signature :
boolean isCacheable()
Description:
Returns a collection corresponding to the attached files of the current or specified content.
See resourcesById
Signature :
Collection contentAttachments()
Collection contentAttachments(String contentId)
Arguments:
Name | Type | Description |
---|---|---|
contentId | String | Unique content identifier |
Description:
Returns labels applied to current content.
Signature:
Collection contentTags()
TODO
TODO
TODO
Description:
Escapes special characters from a string to be compatible with JavaScript.
For example, the line break becomes \n, the " becomes \", etc.
Signature:
String escapeJS(String value)
Arguments:
Name | Type | Description |
---|---|---|
value | String | Value to escape |
Example:
To initialize a variable JavaScript with a value from XML, do not assign it directly, as certain characters (such as quotation marks or line breaks) will not be valid at JavaScript.
<script type="text/javascript"> var name = "{{ escapeJS(name) }}"; </script>
Description:
Scales the text to the next occurrence of a character in the given character set, taking into account a minimum size of the returned text.
Signature:
String splitText (String textToSplit, String tokenizers, int startIndex)
Arguments:
Name | Type | Description |
---|---|---|
textToSplit | String | Text to be split |
tokenizers | String | Delimiter characters |
startIndex | int | Hint in the string at which to start searching for a delimiter character. Corresponds to the minimum size of the return string. |
For example:
{{ splitText ('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quoniam, si dis placet, ab Epicuro loqui discimus.', ',.;', 70) }}
The string returned is "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quoniam, si dis placet"
Description:
Returns the path to a resource file stored in a plugin.
Signature:
String pluginResourceURL(String plugin, String path)
Arguments:
Name | Type | Description |
---|---|---|
plugin | String | Name plugin |
path | String | Path to the plugin |
Example:
<script type="text/javascript" src="{{ pluginResourceURL('web', 'js/jquery.treeview.min.js') }}"/>
Description:
Returns a base 64 encoded image stored in a plugin.
Signature :
String pluginImageBase64(String plugin, String path)
Arguments:
Name | Type | Description |
---|---|---|
plugin | String | Name plugin |
path | String | Image path in the plugin |
Example:
<img src="{{ pluginResourceURL('myplugin', 'img/image.png') }}"/>
TODO
TODO
TODO
Description:
Returns the value of a configuration parameter.
Signature :
String config(String id)
Arguments:
Name | Type | Description |
---|---|---|
id | String | Parameter identifier |
Example:
<script type="text/javascript"> alert("Vous allez recevoir un email de {{ config('smtp.mail.from') }}"); </script>
TODO
TODO
TODO
TODO