CMS Ametys provides integrators with numerous methods accessible from XSLT, facilitating the integration of graphic charters.
For more information, click here.
Add this code to the header of XSL files:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ... xmlns:ametys="org.ametys.web.transformation.xslt.AmetysXSLTHelper" ... extension-element-prefixes="... ametys ...">
So that you can call any of the functions defined below, using "ametys:functionName(argument1, argument2)"
For example:
<xsl:if test="ametys:zone() = 'default'"> <!-- We are in the default zone --> ... </xsl:if>
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("<xsl:value-of select="ametys: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()
Example:
<a href="{ametys:siteUriPrefix()}/{ametys: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 :
Retourne le nom de la charte graphique utilisée par le site courant.
Comme il n'est pas possible de charger une XSL avec une variable, utiliser le protocole skin : <xsl:import href="skin://stylesheets/common.xsl"/>
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="{ametys: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 :
Node skinResources(String path)
Arguments:
Name |
Type |
Description |
---|---|---|
path |
String |
Path in the resources directory of the graphic charter |
Example:
<ul> <xsl:for-each select="ametys:skinResources('img/slideshow')/resource"> <img src="{ametys:skinURL(concat('img/slideshow/', @name))}"/> </xsl:for-each> </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="{ametys: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="ametys: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:
<xsl:variable name="zone" select="ametys:zone('default')"/> <xsl:choose> <xsl:if test="$zone = 'default'"> <!-- Nous sommes dans la zone 'default' --> ... </xsl:when> <xsl:when test="$zone = 'right'"> <!-- Nous sommes dans la zone 'right' --> ... </xsl:when> <xsl:otherwise> <!-- Nous sommes dans la zone 'left' --> ... </xsl:otherwise> </xsl:choose>
Description:
Returns the identifier of the zoneitem currently in use. Useful for rendering content or services.
Note that content rendering can also be viewed outside a page with no associated zoneitem.
Signature :
String zoneItemId ()
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="{ametys:siteUriPrefix()}/{ametys: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".
<xsl:value-of select="ametys:pageTitle(ametys:site(), ametys: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 |
From Ametys 4.4
Description:
Returns the page type: CONTAINER, NODE or LINK
Signature :
String pageType(String pageId)
Arguments:
Name |
Type |
Description |
---|---|---|
pageId |
String |
Page identifier |
From Ametys 4.4
Description:
Returns theurl type of a page of type "LINK": WEB or PAGE or empty if the page is not of type LINK.
See #pageType.
Signature :
String pageUrlType(String pageId)
Arguments:
Name |
Type |
Description |
---|---|---|
pageId |
String |
Page identifier |
From Ametys 4.4
Description:
Returns theurl of a LINK page. See #pageType.
Theurl can be an external url (WEB) or the identifier of a Ametys (PAGE) page. See #pageUrlType
Signature :
String pageUrl(String pageId)
Arguments:
Name |
Type |
Description |
---|---|---|
pageId |
String |
Page identifier |
Description:
Returns the page type: CONTAINER, NODE or LINK
Signature :
String pageType(String pageId)
Arguments:
Name |
Type |
Description |
---|---|---|
pageId |
String |
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. |
From Ametys 4.2
Description:
Returns true if the requested page exists.
Signature :
boolean pageExists(String sitename, String lang, String path)
Arguments:
Name |
Type |
Description |
---|---|---|
sitename |
String |
Site identifier |
lang |
String |
Site language code |
path |
String |
Page path in sitemap |
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 sitename, String lang, String path) // From 3.8.2 only
boolean pageHasRestrictedAccess(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 |
From Ametys 3.8.1
Description:
Determines whether a page is visible. If false, it must not appear in the navigation elements.
Signature :
boolean pageIsVisible (String sitename, String lang, String path) // From 3.8.2 only
boolean pageIsVisible (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 a list of page identifiers corresponding to a tag search, in the form :
<page id="page://xxxx-xxxx-xxxxxxxxx"/> ...
Signature :
Node findPagesIdsByTag(String tag)
Node findPagesIdsByTag(String sitename, String lang, String tag)
Arguments:
Name |
Type |
Description |
---|---|---|
tag |
String |
Page tag identifier in current site and language |
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.
<xsl:variable name="testPages" select="ametys:findPagesIdsByTag('TEST')"/> <xsl:if test="$testPages"> <ul> <xsl:for-each select="$testPages"> <li> <a href="{resolver:resolve('page', @id)}"><xsl:value-of select="ametys:pageLongTitle(@id)"/></a> </li> </xsl:for-each> </ul> </xsl:if>
From Ametys 4.6
Description:
Determines whether captcha protection is required on the current page.
Captcha protection depends on site configuration (form protection policy) and whether access to the page requires authentication or not.
Signature:
public static boolean isCaptchaRequired()
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 a content rendering, the method returns the status of the content with respect to the cache.
If isCacheable is called from skin, the method returns the status of the page with respect to the cache.
Signature :
boolean isCacheable()
Description:
Returns the list of pages referenced by a content item, i.e. the pages on which the content is displayed, along with the view used to render the content.
<page id="page://xxxx-xxxx-xxxx" metadataSetName="main"/> <page id="page://yyyy-yyyy-yyyy" metadataSetName="main"/> <page id="page://zzzz-zzzz-zzzz" metadataSetName="abstract"/>
Signature:
NodeList referencedPages (String contentId)
Arguments:
Name |
Type |
Description |
---|---|---|
contentId |
String |
Unique content identifier |
Description:
Returns the list of pages referenced by a content item, i.e. the pages on which the content is displayed, with the view used to render the content and for which the front-office user has access rights.
<page id="page://xxxx-xxxx-xxxx" metadataSetName="main"/> <page id="page://yyyy-yyyy-yyyy" metadataSetName="main"/> <page id="page://zzzz-zzzz-zzzz" metadataSetName="abstract"/>
Warning
This method should only be used on non-cacheable pages.
Signature:
NodeList accessibleReferencedPages (String contentId)
Arguments:
Name |
Type |
Description |
---|---|---|
contentId |
String |
Unique content identifier |
Description:
Returns the list of pages in the breadcrumb trail, excluding the current page.
<page>page://xxxx-xxxx-xxxx</page> <page>page://yyyy-yyyy-yyyy</page> <page>page://zzzz-zzzz-zzzz</page>
Signature:
NodeList breadcrumb()
Example:
To create a breadcrumb trail
<xsl:if test="ametys:pageId() != ''"><!-- No breadcrumb when there is no current page (content view) --> <ul> <xsl:if test="ametys:pagePath() != 'index' and ametys:pageExists($site, $lang, 'index')"> <!-- Ajoute la page d'accueil au fil d'ariane, si ce n'est pas la page actuelle) <li> <a href="{$site-uri-prefix}/{$lang}/index.html"> <xsl:value-of select="ametys:pageTitle($site, $lang, 'index')"/> </a> </li> </xsl:if> <xsl:for-each select="ametys:breadcrumb()"> <li> <a href="{resolver:resolve('page', .)}"><xsl:value-of select="ametys:pageTitle(.)"/></a> </li> </xsl:for-each> </ul> </xsl:if>
Description:
Returns a DOM node corresponding to the attached files of the current or specified content.
See resourcesById for the DOM description.
Signature:
Node contentAttachments()
Node contentAttachments(String contentId)
Arguments:
Name |
Type |
Description |
---|---|---|
contentId |
String |
Unique content identifier |
Description :
Returns a DOM node containing the labels applied to the current content or to a given content.
The returned node has the following form:
<tag name="TAGNAME"/> ...
Signature:
NodeList contentTags()
NodeList contentTags(String contentId) (from Ametys 4.2)
Arguments:
Name |
Type |
Description |
---|---|---|
contentId |
String |
Unique content identifier |
From Ametys 4.2
Description:
Returns a list of content identifiers corresponding to a tag search, in the form :
<content id="defaultWebContent://xxxx-xxxx-xxxxxxxxx"/> ...
Signature :
Node findContentsIdsByTag(String tag)
Node findContentsIdsByTag(String sitename, String lang, String tag)
Arguments:
Name |
Type |
Description |
---|---|---|
tag |
String |
Identifier of the content tag in the site and current language |
Name |
Type |
Description |
---|---|---|
sitename |
String |
Site name. For example 'www'. The '+' value allows you to search for content from any site. The '^' value is used to search for content without a site. |
lang |
String |
Language code. For example 'fr'. |
tag |
String |
Content label identifier. |
Example:
To create a list of links to content bearing the TEST label.
<xsl:variable name="testContents" select="ametys:findContentsIdsByTag('TEST')"/> <xsl:if test="$testContents"> <ul> <xsl:for-each select="$testContents"> <li> <a href="{resolver:resolve('content', @id)}"><xsl:value-of select="ametys:contentMetadata(@id, 'title', $lang)"/></a> </li> </xsl:for-each> </ul> </xsl:if>
Prefer contentAttribute from Ametys 4.3 onwards
Description :
Returns the string value of a metadata.
2 possible signatures:
Arguments:
Name |
Type |
Description |
---|---|---|
contentId |
String |
Content identifier |
metadataPath |
String |
Metadata path |
lang (optional) |
String |
Language to use if the metadata is multilingual |
From Ametys 4.3
Description
Determines whether an attribute exists on a given content
Signature:
boolean hasValue(String contentId, String dataPath)
Arguments:
Name |
Type |
Description |
---|---|---|
contentId |
String |
Content identifier |
dataPath |
String |
Attribute path |
From Ametys 4.3
Description
Returns the value(s) of an attribute, regardless of its type.
Example of a value returned for an attribute of type "string", multiple :
<keyword>Lorem</keyword> <keyword>ipsum</keyword>
Example of the value returned for an attribute of type "content":
<orgunit createdat="2014-07-23T10:29:51.120+02:00" creator="Anonymous" id="orgunitContent://7d3d2d45-1c26-4fa6-bfa8-deeac4881950" language="fr" lastmodifiedat="2019-04-01T14:18:16.206+02:00" name="orgunit-0340838b" title="UFR Sciences Economiques, Sociales et de Gestion"></orgunit>
Example of the value returned for an attribute of type "content":
<illustration> <image filename="23b.jpg" lastmodified="2019-10-30T14:22:51.00000093Z" mime-type="image/jpeg" path="illustration/image" size="162213" type="metadata"/> </illustration>
2 possible signatures:
Arguments:
Name |
Type |
Description |
---|---|---|
contentId |
String |
Content identifier |
dataPath |
String |
Attribute path |
lang (optional) |
String |
Language to use if the metadata is multilingual |
From Ametys 4.6
Description:
Retrieves an extract of content
Signature:
String contentExcerpt(String contentId, String attributePath, int limit)
Arguments:
Name |
Type |
Description |
---|---|---|
contentId |
string |
Content identifier |
attributePath |
string |
Path of the "richtext" attribute from which the extract will be calculated |
limit |
number |
Maximum number of characters in extract |
Example of use:
<p class="abstract"><xsl:value-of select="ametys:contentExcerpt(@id,'content', 200)"/></p>
From Ametys 4.3
Description:
Retrieves the HTML view of a content
Example:
<content id="defaultWebContent://9936aca4-4933-4daf-a340-8bf3b796aed7" lang="fr" title="Titre du contenu" name="mon_contenu"> <html> <head>...</head> <body>...</body> </html> </content>
Signature:
As not all parameters are mandatory, several signatures are available:
Node getContentView(String contentId)
Node getContentView(String contentId, String viewName)
Node getContentView(String contentId, String viewName, int startHeadingsLevel)
Node getContentView(String contentId, String viewName, int startHeadingsLevel, String lang, boolean checkReadAccess)
Name |
Type |
Description |
---|---|---|
contentId |
String |
Identifier of the content to be displayed |
viewName |
String |
Name of the view to be used. Defaults to main view |
startHeadingsLevel |
String |
Offset to be applied to titles (h1, h2, h3, ....). Par exemples: 3 pour que les titres de plus au niveau soit des <h3> (ie. les <h1> seront transformés en <h3>) |
lang |
String |
Translation language. Only useful if the content to be displayed is multilingual. |
checkReadAccess |
boolean |
Set to true() to check read rights on content. |
Example of use:
<xsl:copy-of select="ametys:getContentView(id)/content/html/body/node()"/>
Warning
When this method is used with one of the first 3 signatures or with the 4th with checkReadAccess=false, read rights are not checked. Make sure you use this method for public content only.
If you use the 4th method with checkReadAccess=true, the rights of the current user are checked, but make sure you don't use this method on a page that can be cached!
Description:
Returns a DOM node corresponding to a resource explorer directory and its contents. The directory is retrieved by its unique identifier.
The returned node has the following form:
<collection name="DIRECTORYNAME" id="DIRECTORYID"> <collection name="SUBDIRECTORY" id="SUBDIRECTORYID"> ... </collection> ... <resource name="FILENAME" id="FILEID" length="LENGTHINBYTES"/> ... </collection>
Optionally, a resource can have the following data:
last-modified="YYYY-MM-DD'T'hh:mm:ss'Z'"
Signature :
Node resourcesById(String collectionId)
Arguments:
Name |
Type |
Description |
---|---|---|
collectionId |
String |
Unique identifier for a resource explorer directory |
Example:
<xsl:for-each select="ametys:resourcesById($resourcesId)/resource"> ... </xsl:for-each>
Description:
Same as resourcesById but using the local path (directory tree) in the current site's resource explorer.
See resourcesById for the DOM description.
Signature :
Node resourcesByPath(String path)
Arguments:
Name |
Type |
Description |
---|---|---|
path |
String |
Resource explorer directory path |
Example:
<xsl:if test="ametys:resourcesByPath('Fonds')/resource[@name = 'default.jpg']"> <img src="{resolver:resolve('explorer', ametys:resourcesByPath('Fonds')/resource[@name = 'default.jpg']/@id)}"/> </xsl:if>
Description:
Returns the translated label of a given tag.
Signature :
String tagLabel(String siteName, String tagName, String lang)
Arguments:
Name |
Type |
Description |
---|---|---|
siteName |
String |
Site identifier |
tagName |
String |
Label name |
lang |
String |
Code of the language used to translate the label, if possible. Contributor (custom) labels are available in one language only, but labels provided by plugins or the charter are in principle internationalized. |
Example:
This code returns the translated wording of the SECTION label ('Section', 'Rubrique'...).
<xsl:value-of select="ametys:tagLabel(ametys:site(), 'SECTION', ametys:lang())"/>
Description :
Returns the translated description of a given label.
Signature :
String tagDescription(String siteName, String tagName, String lang)
Arguments:
Name |
Type |
Description |
---|---|---|
siteName |
String |
Site identifier |
tagName |
String |
Label name |
lang |
String |
Code of the language used to translate the description, if possible. Contributor tags (custom tags) are only available in one language, but tags provided by plugins or the charter are in principle internationalized. |
Description :
Returns the visibility ('private' or 'public') of a given label.
Signature :
String tagVisibility(String siteName, String tagName)
Arguments:
Name |
Type |
Description |
---|---|---|
siteName |
String |
Site identifier |
tagName |
String |
Label name |
Description :
Returns the identifier of the parent label.
If the label has no parent label, the empty string is returned.
Signature :
String tagParent(String siteName, String tagName)
Arguments:
Name |
Type |
Description |
---|---|---|
siteName |
String |
Site identifier |
tagName |
String |
Label name |
Description:
Returns the path of the label, up to the highest-level parent.
The path is composed of the names of the parent labels, separated by '/'
If the label does not exist, the empty string is returned.
Signature :
String tagPath(String siteName, String tagName)
Arguments:
Name |
Type |
Description |
---|---|---|
siteName |
String |
Site identifier |
tagName |
String |
Label name |
Description:
Returns the colors associated with the label.
The result XML will be in the form:
<color> <main>#FF66FF</main> <text>#FFFFFF</text> </color>
If the label does not exist or it is not possible to add a color to the label, the empty string is returned.
Signature :
String tagColor(String siteName, String tagName)
Arguments:
Name |
Type |
Description |
---|---|---|
siteName |
String |
Site identifier |
tagName |
String |
Label name |
Description:
Returns the context of the current rendering:
This can be used to display warning messages during preview without displaying them to the final visitor.
Signature :
String renderingContext()
Example:
<xsl:variable name="dest"> <xsl:choose> <xsl:when test="ametys:renderingContext() = 'back'"> <xsl:text>javascript:alert("Cette fonctionnalité ne peut pas être utilisée dans le back-office. Ouvrez la prévisualisation pour l'utiliser.");</xsl:text> </xsl:when test> <xsl:otherwise> <xsl:value-of select="@href"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <a href="{$dest}>Ouvrir</a>
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 = "<xsl:value-of select="ametys: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. |
For example:
<xsl:value-of select="ametys: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"
From Ametys 4.1
Description:
Extracts the value associated with a key from a Map object in JSON
format. The expected value must be a string, integer, decimal or date.
Signature :
String getValueFromJsonObject(String jsonString, String key)
Arguments:
Name |
Type |
Description |
---|---|---|
jsonString |
String |
representation JSON of the Map object |
key |
String |
value key to retrieve |
For example:
In the example below, the JS variable 'groupId' is set to 'a27f45sd'.
<script type="text/javascript"> <xsl:variable name="group">{"groupId": "a27f45sd", "groupDirectory": "group-sql"}</xsl:variable> <xsl:variable name="groupId" select="ametys:getValueFromJsonObject($group, 'groupId')"/> var groupId = "<xsl:value-of select="$groupId"/>" </script>
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="{ametys: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="{ametys:pluginResourceURL('myplugin', 'img/image.png')}"/>
Description:
Returns the current site map or part of the site map under the page specified in the parameter. Visible pages are those that the user can see if there is an access limitation. Invisible sub-pages are not returned (unless explicitly requested from Ametys 4.1.1 onwards).
The DOM tree returned has the following form:
<sitemap sitemap:site="www" sitemap:lang="fr" xmlns:sitemap="http://www.ametys.org/inputdata/sitemap/3.0"> <page sitemap:id="page://uniqueid" sitemap:name="index" sitemap:title="Accueil" sitemap:long-title="Accueil" sitemap:path="index"> <page .../> ... </page> ... </sitemap>
The page tag contains the following attributes, depending on the type of page:
sitemap:type="CONTAINER" sitemap:container="true" OR sitemap:type="NODE" OR sitemap:type="LINK" sitemap:link="http://www.ametys.org" sitemap:link-type="WEB" OR sitemap:type="LINK" sitemap:link="page://uniqueid" sitemap:link-type="PAGE"
The page tag contains the following attributes, which depend on the page being viewed:
sitemap:in-path="true" // si la page est dans le fil d'ariane (peut être la page courant) sitemap:current="true" // si la page est la page courante
The page tag contains the tags applied to it, prefixed with PLUGIN_TAGS_ :
PLUGIN_TAGS_SECTION="empty" // if the page has the "SECTION" tag
In the page tag, if the page is restricted, you'll find the sitemap:restricted attribute
sitemap:restricted="true" // if the page has a restricted access
As of v4.1.1, if the page is invisible (hidden from navigation elements), the sitemap:invisible attribute is added to the page tag.
sitemap:invisible="true" // if the page should be hidden from menus
The page tag contains all the page's metadata (except composite, binary, richtext and multiple-value metadata).
metadataName="value"
To access the attributes, remember to declare the following namespace on your xsl : xmlns:sitemap="http://www.ametys.org/inputdata/sitemap/3.0"
Signature:
Node sitemap(long depth) - From Ametys 4.3.12
Node sitemap(long depth, boolean includeInvisiblePages)- From Ametys 4.3.12
Node sitemap (String pageId, long depth)- From Ametys 4.3.12
Node sitemap (String pageId, long depth, boolean includeInvisiblePages) - From Ametys 4.3.12
Node sitemap() - No longer used from Ametys 4 .3.12 for performance reasons; no longer available fromAmetys 4. 4.0
Node sitemap(boolean includeInvisiblePages) - No longer used from Ametys 4 .3.12 for performance reasons; no longer available fromAmetys 4.4.0
Node sitemap (String pageId) - No longer used from Ametys 4 .3.12 for performance reasons; no longer available fromAmetys 4 .4.0
Node sitemap (String pageId, boolean includeInvisiblePages) - No longer used from Ametys 4 .3.12 for performance reasons; no longer available fromAmetys 4 .4.0
Arguments:
Name |
Type |
Description |
---|---|---|
pageId |
String |
Page identifier |
depth |
long |
Depth to be displayed |
includeInvisiblePages |
boolean |
Displays invisible subpages |
Example:
<ul> <xsl:for-each select="ametys:sitemap(1)/page"> <li><xsl:value-of select="@sitemap:title"/></li> </xsl:for-each> </ul>
Performance
Warning! The use of ametys:sitemap(-1) is very costly. If you have no other choice, we strongly advise you to declare it only once at the top of a XSL that uses it.
Whenever possible, use the version with pageId or search by label, for example.
Description :
Key translation i18n
Signature:
String translate(String i18nkey)
String translate(String i18nkey, String lang, NodeList i18nparams)
Arguments:
Name |
Type |
Description |
---|---|---|
i18nkey |
String |
key i18n with catalog name |
lang |
String |
translation language. If null, the current language will be used |
i18nparams |
NodeList |
Parameter list i18n. Can be empty or null |
Example of use:
<xsl:variable name="i18nparams"><count><xsl:value-of select="$count"/></count></xsl:variable> <xsl:value-of select="ametys:translate(concat('skin.', $skin, ':SKIN_CONTENT_NB_LIKES_TOOLTIP'), $lang, $i18nparams)"/>
Description:
Returns a DOM node corresponding to the logged-in user.
This method lets you know whether a user is logged in.
This method must not be called in a cacheable environment (cacheable service, content, etc.).
The DOM returned depends on the UsersManager used (LDAP, SQL, other...).
Here is a description of what can be returned by the StaticUsersManager (the one used by the demo with hard-coded users) or the JDBCUsersManager (the one whose users are stored in a database SQL):
<user login="USERLOGIN" population="USERPOPULATION"> <firstname>FIRSTNAME</firstname> <lastname>LASTNAME</lastname> <email>EMAIL</email> <fullname>FULLNAME</fullname> <sortablename>SORTABLENAME</sortablename> <populationLabel>POPULATIONLABEL</populationLabel> </user>
Signature:
Node user()
Node user(String userIdentity)
Node user(String login, String populationId)
Arguments:
Name |
Type |
Description |
---|---|---|
userIdentity |
String |
User ID in the form: login#populationId |
Name |
Type |
Description |
---|---|---|
login |
String |
User ID |
populationId |
String |
User population identifier |
Example:
To obtain the values returned in a given environment, run the following code on a limited page (to avoid caching problems and empty results) and analyze the source code generated.
<MARKER><xsl:copy-of select="ametys:user()"/></MARKER>
Description : Returns a list of DOM nodes corresponding to the groups of the logged-in user or a given user. This method must not be called in a cacheable environment (cacheable service, content, etc.).
<group name="group1" directory="directory1"/> <group name="group2" directory="directory2"/>
Signatures :
NodeList groups()
NodeList groups(String userIdentity)
NodeList groups(String login, String populationId)
Arguments:
Name |
Type |
Description |
---|---|---|
userIdentity |
String |
User ID in the form: login#populationId |
Name |
Type |
Description |
---|---|---|
login |
String |
User ID |
populationId |
String |
User population identifier |
Example: To obtain the values returned in a given environment, run the following code on a limited page (to avoid caching problems and empty results) and analyze the source code generated.
<MARKER> <xsl:for-each select="ametys:groups()"> <GROUP><xsl:value-of select="@name"/>#<xsl:value-of select="@directory"/></GROUP> </xsl:for-each> </MARKER>
From Ametys 4.2
Description : Returns a structure XML that can be used to easily create a pagination with separators of the type
|< < 1 2 ... 5 6 7 ... 10 11 > >|
The element types returned are :
<gotofirstpage enabled="true|false">1</gotofirstpage> <gotopreviouspage enabled="true|false">5</gotopreviouspage> <page>1</page> <current>2</current> <space/> <separator/> <gotonextpage enabled="true|false">7</gotonextpage> <gotolastpage enabled="true|false">12</gotolastpage>
On considère que les séparateurs prennent une place (comme un numéro de page) et donc si vous demandez:
2 numéros puis 1 séparateur puis 3 numéros puis 1 séparateur puis 2 numéros
avec 9 pages de résultats vous obtiendrez |< < 1 2 3 4 5 6 7 8 9 > >|
avec 10 pages de résultats vous obtiendrez |< < 1 2 ... 5 6 7 8 9 10 > >|
avec 11 pages de résultats vous obtiendrez |< < 1 2 ... 5 6 7 ... 10 11 > >|
Signatures :
NodeList pagination(int nbPages, int currentPage, int nbFirstPages, int nbCentralPages, int nbLastPages)
Arguments:
Name |
Type |
Description |
---|---|---|
nbPages |
int |
Total number of result pages |
currentPage |
int |
The number of the current results page |
nbFirstPages |
int |
La taille du premier lot de pages (entre le bouton < et le premier séparateur) |
nbCentralPages |
int |
The size of the central batch of pages (between the two separators) |
nbLastPages |
int |
Size of last batch of pages (after last separator) |
Exemple : Pour créer une pagination du type |< < ... 4 5 6 7 8 ... > >|
ametys:pagination(12, 6, 0, 5, 0)
<gotofirstpage enabled="true">1</gotofirstpage> <gotopreviouspage enabled="true">5</gotopreviouspage> <separator/> <page>4</page> <page>5</page> <current>6</current> <page>7</page> <page>8</page> <separator/> <gotonextpage enabled="true">7</gotonextpage> <gotolastpage enabled="true">12</gotolastpage>
ametys:pagination(6, 6, 0, 5, 0)
<gotofirstpage enabled="true">1</gotofirstpage> <gotopreviouspage enabled="true">5</gotopreviouspage > <page>1</page> <page>2</page> <page>3</page> <page>4</page> <page>5</page> <current>6</current> <gotonextpage enabled="false"></gotonextpage> <gotolastpage enabled="false">6</gotolastpage>
Description:
Determines whether the current display is the front edition mode (as defined by plugin Front Edition) or not.
Signature :
boolean isEditionMode()
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 <xsl:value-of select="ametys:config('smtp.mail.from')"/>"); </script>
From Ametys 4.8
Description:
Returns the list of languages available for a site
<lang>fr</lang> <lang>en</lang>
Signature :
NodeList siteLanguages()
NodeList siteLanguages(String siteName)
Arguments:
Name |
Type |
Description |
---|---|---|
siteName |
String |
Site name or current site if empty |
Description:
Returns the value of a site parameter.
Signature :
String siteParameter(String parameter)
Arguments:
Name |
Type |
Description |
---|---|---|
parameter |
String |
Parameter identifier |
Example:
<script type="text/javascript"> var googleAnalyticsIdentifier = "<xsl:value-of select="ametys:siteParameter('site-param-google-web-property-id')"/>"; </script>
Description:
Returns the DOM node representing the value of the service parameter currently being rendered.
This method should only be called when rendering a service.
Possibly add a default value (optional).
Signature :
Node serviceParameter (String parameter)
Node serviceParamter (String parameter, String defaultValue)
Arguments:
Name |
Type |
Description |
---|---|---|
parameter |
String |
Service parameter identifier |
Name |
Type |
Description |
---|---|---|
parameter |
String |
Service parameter identifier |
defaultValue |
String |
If the value is empty, the default value is returned (this can happen, for example, when a new service parameter is added to remain compatible with existing data. If the parameter is of composite type, the default value will not be used. |
The DOM tree returned for a single parameter has the following form:
<header name="header" type="string">Mon titre de service</header>
The DOM tree returned for a compound parameter has the following form:
<search name="search" type="composite"> <_x0031_ name="1" type="composite"> <sites>www</sites> <tags name="tags" type="string">TAG1</tags> <lang-context name="lang-context" type="string">CURRENT</lang-context> </_x0031> </search>
Example:
<h1><xsl:value-of select="ametys:serviceParameter('header')"/><h1>
<xsl:value-of select="ametys:serviceParameter('search')/*/tags"/>
Description:
Returns all parameters of the service being rendered in the form of a DOM tree.
This method should only be called when rendering a service.
Signature :
Node serviceParameters ()
The DOM abbreviation returned has the following form:
<serviceParameters> <header name="header" type="string">My title</header> <nb-max name="nb-max" type="string">5</nb-max> <search name="search" type="composite"> <_x0031_ name="1" type="composite"> <tags name="tags" type="string">TAG1,TAG2</tags> <site name="site" type="string">www</site> </_x0031> <_x0032_ name="2" type="composite"> <tags name="tags" type="string">TAG3</tags> <site name="site" type="string">blog</site> </_x0032> </search> </serviceParameters>
Example:
<h1><xsl:value-of select="ametys:serviceParameters()/header"/></h1>
Description:
Returns the value of a query parameter.
Warning! This should only be used in non-cacheable XSL (such as non-cacheable services). Otherwise, the result of the first visitor will be used for all other visitors...
Signature :
String requestParameter(String parameter)
Arguments:
Name |
Type |
Description |
---|---|---|
parameter |
String |
Parameter name |
Example:
For the followingURL : http: //www.ametys.org/en/index.html?id=3
<input type="hidden" name="id" value="{ametys:requestParameter('id')}"/>
Description:
Returns a list of view parameters for the current template that have a value. This list takes parameter inheritance into account.
If there are none, the list is empty.
Signature :
NodeList templateParameters ()
Back to top:
Type |
Description |
---|---|
NodeList |
A list of all view parameters in the current template that have a value. This list takes into account parameter inheritance |
Example:
<param1>valeur1</param1> <param2>valeur2</param2> // Ce paramètre est multiple <param2>valeur3</param2> <param3> <longitude>0.0<longitude> <latitude>1.0<latitude> </param3>
Description :
Returns the value of the given view parameter on the current template. It will automatically take inheritance into account, if any.
If there is no value or the parameter path is invalid, it returns null.
Signature :
NodeList templateParameter (String parameterPath)
Arguments:
Name |
Type |
Description |
---|---|---|
parameterPath |
String |
View parameter path |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns the value of the given view parameter on the current template. It will automatically take inheritance into account, if any. |
Example:
<param>value</param>
Description :
Returns the value of the view parameter given on the page template given as an argument. It will automatically take inheritance into account, if any.
If there is no value, or the parameter path is invalid, or the page ID is wrong, it returns null.
Signature :
NodeList templateParameter (String pageId, String parameterPath)
Arguments:
Name |
Type |
Description |
---|---|---|
pageId |
String |
Page identifier JCR |
parameterPath |
String |
View parameter path |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns the value of the view parameter given on the page template given as an argument. It will automatically take inheritance into account, if any. |
Example:
<param>value</param>
Description:
Returns the list of view parameters in the current zone that have a value. This list takes parameter inheritance into account.
If there are none, the list is empty.
Signature :
NodeList zoneParameters ()
Back to top:
Type |
Description |
---|---|
NodeList |
Returns a list of view parameters in the current zone that have a value. This list takes parameter inheritance into account. |
Example:
<param1>valeur1</param1> <param2>valeur2</param2> // Ce paramètre est multiple <param2>valeur3</param2> <param3> <longitude>0.0<longitude> <latitude>1.0<latitude> </param3>
Description:
Returns the list of view parameters, for the current page on the zone given as an argument, which have a value. This list takes parameter inheritance into account.
If there are none, the list is empty.
Signature :
NodeList zoneParameters (String zoneName)
Arguments:
Name |
Type |
Description |
---|---|---|
zoneName |
String |
Zone name |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns the list of view parameters, for the current page on the zone given as an argument, which have a value. This list takes parameter inheritance into account. |
Example:
<param1>valeur1</param1> <param2>valeur2</param2> // Ce paramètre est multiple <param2>valeur3</param2> <param3> <longitude>0.0<longitude> <latitude>1.0<latitude> </param3>
Description :
Returns the value of the given view parameter on the current zone. It will automatically take inheritance into account, if any.
If there is no value or the parameter path is invalid, it returns null.
Signature :
NodeList zoneParameter (String parameterPath)
Arguments:
Name |
Type |
Description |
---|---|---|
parameterPath |
String |
View parameter path |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns the value of the given view parameter on the current zone. It will automatically take inheritance into account, if any. |
Example:
<param>value</param>
Description :
Returns the value of the given view parameter on the zone given as an argument to the current page. It will automatically take inheritance into account, if any.
If there is no value, the parameter path is invalid or the zone does not exist, it returns null.
Signature :
NodeList zoneParameter (String zoneName, String parameterPath)
Arguments:
Name |
Type |
Description |
---|---|---|
zoneName |
String |
Zone name |
parameterPath |
String |
View parameter path |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns the value of the given view parameter on the zone given as an argument to the current page. It will automatically take inheritance into account, if any. |
Example:
<param>value</param>
Description :
Returns the value of the given view parameter on the page and zone given as argument. It will automatically take inheritance into account, if any.
If there is no value, or the parameter path is invalid, or the zone or page does not exist, it returns null.
Signature :
NodeList zoneParameter (String pageId, String zoneName, String parameterPath)
Arguments:
Name |
Type |
Description |
---|---|---|
pageId |
String |
Page identifier JCR |
zoneName |
String |
Zone name |
parameterPath |
String |
View parameter path |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns the value of the given view parameter on the page and zone given as argument. It will automatically take inheritance into account, if any. |
Example:
<param>value</param>
Description:
Returns a list of view parameters for the current item zone that have a value.
If there are none, the list is empty.
Signature :
NodeList zoneItemParameters ()
Back to top:
Type |
Description |
---|---|
NodeList |
Returns a list of view parameters for the current item zone that have a value. |
Example:
<param1>valeur1</param1> <param2>valeur2</param2> // Ce paramètre est multiple <param2>valeur3</param2> <param3> <longitude>0.0<longitude> <latitude>1.0<latitude> </param3>
Description :
Returns a list of view parameters for the item zone given as an argument, which have a value.
If there are none, the list is empty.
Signature :
NodeList zoneItemParameters (String zoneItemId)
Arguments:
Name |
Type |
Description |
---|---|---|
zoneItemId |
String |
The JCR identifier of the item zone |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns a list of view parameters for the item zone given as an argument, which have a value. |
Example:
<param1>valeur1</param1> <param2>valeur2</param2> // Ce paramètre est multiple <param2>valeur3</param2> <param3> <longitude>0.0<longitude> <latitude>1.0<latitude> </param3>
Description :
Returns the value of the given view parameter on the current item zone.
If there is no value or the parameter path is invalid, it returns null.
Signature :
NodeList zoneItemParameter (String parameterPath)
Arguments:
Name |
Type |
Description |
---|---|---|
parameterPath |
String |
View parameter path |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns the value of the given view parameter on the current item zone. |
Example:
<param>value</param>
Description :
Returns the value of the given view parameter and item zone.
If there is no value or the parameter path is invalid, it returns null.
Signature :
NodeList zoneItemParameter (String zoneItemId, String parameterPath)
Arguments:
Name |
Type |
Description |
---|---|---|
zoneItemId |
String |
The JCR identifier of the item zone |
parameterPath |
String |
View parameter path |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns the value of the given view parameter and item zone. |
Example:
<param>value</param>
Description :
Returns a list of view parameters for the current service that have a value.
If there are none, the list is empty.
Signature :
NodeList serviceViewParameters()
Back to top:
Type |
Description |
---|---|
NodeList |
Returns a list of view parameters for the current service that have a value. |
Example:
<param1>valeur1</param1> <param2>valeur2</param2> // Ce paramètre est multiple <param2>valeur3</param2> <param3> <longitude>0.0<longitude> <latitude>1.0<latitude> </param3>
Description :
Returns the value of the view parameter given on the current service
If there is no value or the parameter path is invalid, it returns null.
Signature :
NodeList serviceViewParameter (String parameterPath)
Arguments:
Name |
Type |
Description |
---|---|---|
parameterPath |
String |
View parameter path |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns the value of the view parameter given on the current service |
Example:
<param>value</param>
Description :
Returns a list of view parameters in the current content that have a value.
If there are none, the list is empty.
Signature :
NodeList contentViewParameters()
Back to top:
Type |
Description |
---|---|
NodeList |
Returns a list of view parameters in the current content that have a value. |
Example:
<param1>valeur1</param1> <param2>valeur2</param2> // Ce paramètre est multiple <param2>valeur3</param2> <param3> <longitude>0.0<longitude> <latitude>1.0<latitude> </param3>
Description:
Returns the value of the view parameter given on the current content.
If there is no value or the parameter path is invalid, it returns null.
Signature :
NodeList contentViewParameter (String parameterPath)
Arguments:
Name |
Type |
Description |
---|---|---|
parameterPath |
String |
View parameter path |
Back to top:
Type |
Description |
---|---|
NodeList |
Returns the value of the view parameter given on the current content |
Example:
<param>value</param>