CMS Ametys provides integrators with numerous Twig functions that can be used directly in templates, facilitating the integration of graphic charters.

  1. Reference
    1. Prefixes URL / Application context
      1. uriPrefix
      2. absoluteUriPrefix
      3. siteUriPrefix
      4. absoluteSiteUriPrefix
    2. Skin
      1. skin
      2. skinURL
      3. skinResources
      4. skinImageBase64
      5. template
      6. templateURL
      7. zone
    3. Page
      1. site
      2. lang
      3. pagePath
      4. pageId
      5. pageTitle
      6. pageLongTitle
      7. pageMetadata
      8. pageHasRestrictedAccess
      9. findPagesIdsByTag
      10. isCacheable
    4. Contents
      1. contentAttachments
      2. contentTags
    5. Resource Explorer
    6. Labels
    7. Miscellaneous
      1. renderingContext
      2. escapeJS
      3. splitText
      4. pluginResourceURL
      5. pluginImageBase64
      6. sitemap
      7. user
      8. groups
    8. Parameters
      1. config
      2. siteParameter
      3. serviceParameter
      4. serviceParameters
      5. requestParameter

Reference

Prefixes URL / Application context

uriPrefix

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);

absoluteUriPrefix

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()

siteUriPrefix

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>

absoluteSiteUriPrefix

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

Skin

skin

Description :
Returns the name of the graphic charter used by the current site.

Signature :
String skin()

skinURL

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') }}"/>

skinResources

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>

skinImageBase64

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') }}" />

template

Description:
Returns the name of the template currently in use.

Signature :
String template()

templateURL

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') }}"/>

zone

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 %}

Page

site

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

lang

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>

pagePath

Description:
Returns the path to the current page. This path is relative to the site map.

Signature :
String pagePath()

pageId

Description:
Returns the unique identifier of the current page (in the form page://...).

Signature :
String pageId()

pageTitle

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
langStringSite language code
pathStringPage 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') }}

pageLongTitle

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

langStringSite language code
pathStringPage path in sitemap

Name

Type

Description

pageId

String

Unique page identifier

pageMetadata

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

langStringSite language code
pathStringPage path in sitemap
metadateNameStringMetadata name. Use the '/' character to access composite metadata.

Name

Type

Description

pageId

String

Unique page identifier

metadataNameStringMetadata name. Use the '/' character to access composite metadata.

pageHasRestrictedAccess

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

findPagesIdsByTag

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'.

langStringLanguage code. For example 'fr'.
tagString

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 %}

isCacheable

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()

 

Contents

contentAttachments

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

contentTags

Description:
Returns labels applied to current content.

Signature:
Collection contentTags() 

Resource Explorer

TODO

Labels

TODO

Miscellaneous

renderingContext

TODO

escapeJS

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>

splitText

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:

NameTypeDescription
textToSplitStringText to be split
tokenizersStringDelimiter characters
startIndexintHint 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"

pluginResourceURL

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

pathStringPath to the plugin

Example:

<script type="text/javascript" src="{{ pluginResourceURL('web', 'js/jquery.treeview.min.js') }}"/>

pluginImageBase64

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

pathStringImage path in the plugin

Example:

<img src="{{ pluginResourceURL('myplugin', 'img/image.png') }}"/>

sitemap

TODO

user

TODO

groups

TODO

 

Parameters

config

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>

siteParameter

TODO

serviceParameter

TODO

serviceParameters

TODO

requestParameter

TODO

Back to top