This helper is here to grant you access to a lot of features from any XSLT file (content type rendering, service rendering...). It is available from version 3.3.
Add this in your xslt header
<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 ...">
You can then call any of the following XSLT functions using "ametys:functionName(argument1, argument2)"
Example :
<xsl:if test="ametys:zone() = 'default"> <!-- We are in the default zone --> ... </xsl:if>
Description :
Returns the server url prefix to root path, relatively to server. E.g. '', '/cms', '/cms/preview'.
This can be used to access server for AJAX requests.
Can be empty if the application is at root of the domain name.
Signature :
String uriPrefix()
Sample :
$j.post("<xsl:value-of select="ametys:uriPrefix()"/>/plugins/cms/comments/add-comment", data, result);
Description :
Same as uriPrefix but absolutly. E.g. 'http://www.ametys.org' or 'http://www.ametys.org/cms' or 'http://www.ametys.org/cms/preview'.
Signature :
String absoluteUriPrefix()
Description :
Returns the server url prefix to root path of the current site - if used with no argument -, or of the given site passed in argument, relatively to server. E.g. '', '/cms/www', '/cms/preview/www'.
This can be used to build page path.
Can be empty if the application is at root of the domain name on the site.
Signature :
String siteUriPrefix()
String siteUriPrefix(String siteName)
Arguments :
Name | Type | Description |
---|---|---|
siteName | String | The name of the site |
Sample :
<a href="{ametys:siteUriPrefix()}/{ametys:lang()}/index.html">Accueil</a> <a href="{ametys:siteUriPrefix('www')}/{ametys:lang()}/index.html">Accueil</a>
Description :
Same as siteUriPrefix but absolutly. E.g. 'http://www.ametys.org' or 'http://www.ametys.org/cms/www' or 'http://www.ametys.org/cms/preview/www'.
Use full when you need the web site url (to create "I like facebook" button for example)
Signature :
String absoluteUriPrefix()
String absoluteUriPrefix(String siteName)
Arguments :
Name | Type | Description |
---|---|---|
siteName | String | The name of the site |
Description :
Returns the name of the skin used in the current site.
As it is not possible to load a XSL using a variable , you can use the template protocol. e.g. <xsl:import href="skin://stylesheets/common.xsl"/>
Signature :
String skin()
Description :
Returns the path to a resource file of the skin.
Signature :
String skinURL(String path)
Arguments :
Name | Type | Description |
---|---|---|
path | String | A path in the directory structure of the skin (under the resources directory) |
Sample :
Insert an image located in the directory "skins/MYSKIN/resources/img/myimage.png"
<img src="{ametys:skinURL('img/myimage.png')}"/>
Description :
Returns a DOM representing a directory of the resources subdirectory of the current skin.
This allows for example to have a slideshow of the images of a directory without knowing the name of every file.
See resourcesById to see the DOM description.
Signature :
Node skinResources(String path)
Arguments :
Name | Type | Description |
---|---|---|
path | String | A path in the directory structure of the skin (under the resources directory) |
Sample :
<ul> <xsl:for-each select="ametys:skinResources('img/slideshow')/resource"> <img src="{ametys:skinURL(concat('img/slideshow/', @name))}"/> </xsl:for-each> </ul>
Signature :
String template()
Description :
Returns the path to a resource file of the current template of the skin
Signature :
String templateURL(String path)
Arguments :
Name | Type | Description |
---|---|---|
path | String | A path in the directory structure of the template of the skin (under the resources directory) |
Sample : Insert an image located in the directory "skins/MYSKIN/templates/CURRENTTEMPLATE/resources/img/myimage.png"
<img src="ametys:templateURL('img/myimage.png')"/>
Description :
Returns the name of the zone currently processed. Can be used in a service or content rendering.
But keep in mind that a content rendering can be done outside of any page and have no zone associated : you can set a default value
Signature :
String zone (String defaultValue)
Arguments :
Name | Type | Description |
---|---|---|
defaultValue | String | The default value returned if no zone is currently processed |
Sample :
<xsl:variable name="zone" select="ametys:zone('default')"/> <xsl:choose> <xsl:if test="$zone = 'default'"> <!-- We are in the default zone --> ... </xsl:when> <xsl:when test="$zone = 'right'"> <!-- We are in the right zone --> ... </xsl:when> <xsl:otherwise> <!-- We are in the left zone --> ... </xsl:otherwise> </xsl:choose>
Description :
Returns the identifier of the site holding the current page.
Signature :
String site()
Description :
Returns the language code of the page currently processed
Signature :
String lang()
Sample :
<a href="{ametys:siteUriPrefix()}/{ametys:lang()}/index.html">Home</a>
Description :
Returns the path of the current page. The path is relative to the current sitemap.
Signature :
String pagePath()
Description :
Returns the id of the current page.
Signature :
String pageId()
Description :
Returns the readeable title of a page
Signature :
String pageTitle(String sitename, String lang, String path)
String pageTitle(String pageId)
Arguments :
Name | Type | Description |
---|---|---|
sitename | String | The identifier of a site |
lang | String | The language code in the site |
path | String | The page path in the language sitemap of the site |
Name | Type | Description |
---|---|---|
pageId | String | A page unique identifier |
Sample :
This will returns the title of the index page. Such as 'Home' or 'Accueil'.
<xsl:value-of select="ametys:pageTitle(ametys:site(), ametys:lang(), 'index')"/>
Description :
The same as pageTitle but returning the "long" title of a page.
Note that if no long title is specified, the title will be returned.
Signature :
String longPageTitle(String sitename, String lang, String path)
String longPageTitle(String pageId)
Arguments :
Name | Type | Description |
---|---|---|
sitename | String | The identifier of a site |
lang | String | The language code in the site |
path | String | The page path in the language sitemap of the site |
Name | Type | Description |
---|---|---|
pageId | String | A page unique identifier |
Description :
Returns as a string the value of a metadata of a page.
Signature :
String pageMetadata (String sitename, String lang, String path, String metadataName)
String pageMetadata (String pageId, String metadataName)
Signature :
String pageTitle(String sitename, String lang, String path)
String pageTitle(String pageId)
Arguments :
Name | Type | Description |
---|---|---|
sitename | String | The identifier of a site |
lang | String | The language code in the site |
path | String | The page path in the language sitemap of the site |
metadateName | String | The name of the metadata. Use '/' character to describe composite metadata. |
Name | Type | Description |
---|---|---|
pageId | String | A page unique identifier |
metadataName | String | The name of the metadata. Use '/' character to describe composite metadata. |
Description :
Return false if a page is public, true otherwise.
Signature :
boolean pageHasRestrictedAccess(String pageId)
Arguments :
Name | Type | Description |
---|---|---|
pageId | String | A page unique identifier |
Description :
Returns a DOM corresponding to the attached files of the current content or a specified content.
The returned DOM description is the same as in resourcesById.
Signature :
Node contentAttachments()
Node contentAttachments(String contentId)
Arguments :
Name | Type | Description |
---|---|---|
contentId | String | The unique identifier of a content |
Description :
Returns a DOM of the tags applied to the current content.
The return DOM is like :
<tag name="TAGNAME"/> ...
Signature :
NodeList contentTags()
Description :
Returns a dom corresponding to a path of the resource explorer. The directory is given by its id.
The returned DOM is like
<collection name="DIRECTORYNAME" id="DIRECTORYID"> <collection name="SUBDIRECTORY" id="SUBDIRECTORYID"> ... </collection> ... <resource name="FILENAME" id="FILEID" length="LENGTHINBYTES"/> ... </collection>
Optionnally a resource can have:
last-modified="YYYY-MM-DD'T'hh:mm:ss'Z'"
Signature :
Node resourcesById(String collectionId)
Arguments :
Name | Type | Description |
---|---|---|
collectionId | String | The UUID of a directory of the resources explorer |
Sample :
<xsl:for-each select="ametys:resourcesById($resourcesId)/resource"> ... </xsl:for-each>
Description :
Like resourcesById but using a path local to the resources explorer of the current site.
See resourcesById for the DOM format.
Signature :
Node resourcesByPath(String path)
Arguments :
Name | Type | Description |
---|---|---|
path | String | A path to a directory of the resources explorer |
Description : Returns a human readable label of a given tag
Signature : String tagLabel(String siteName, String tagName, String lang)
Arguments :
Name | Type | Description |
---|---|---|
siteName | String | The identifier of a site |
tagName | String | The name of a tag for this site |
lang | String | The language code to use to translate the label if possible. The contributor tags labels are available in only one language, but tags provided by plugins or skins may be internationalized. |
Sample :
This will returns the beautiful name for SECTION ('Section', 'Rubrique'...)
<xsl:value-of select="ametys:tagLabel(ametys:site(), 'SECTION', ametys:lang())"/>
Description :
Returns a human readable description of a given tag
Signature :
String tagDescription(String siteName, String tagName, String lang)
Arguments :
Name | Type | Description |
---|---|---|
siteName | String | The identifier of a site |
tagName | String | The name of a tag for this site |
lang | String | The language code to use to translate the description if possible. The contributor tags description are available in only one language, but tags provided by plugins or skins may be internationalized. |
Description :
Returns the identifier of the category of a tag. The category of a tag is its parent.
This method allows to know if a tag (e.g. applied to the current content) is part of a know category.
Signature :
String tagCategory(String siteName, String tagName)
Arguments :
Name | Type | Description |
---|---|---|
siteName | String | The identifier of a site |
tagName | String | The name of a tag for this site |
Description :
Returns the current rendering context :
This allows for example to display warning messages in preview situations without displaying to final visitor.
Signature :
String renderingContext()
Sample:
<xsl:variable name="dest"> <xsl:choose> <xsl:when test="ametys:renderingContext() = 'back'"> <xsl:text>javascript:alert("This feature cannot be used in the back-office. Open the preview to use it");</xsl:text> </xsl:when test> <xsl:otherwise> <xsl:value-of select="@href"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <a href="{$dest}>Open</a>
Description :
Escape caracters from a string to be javascript compatible.
E.G. change linebreak to \n, change " to \"...
Signature :
String escapeJS(String value)
Arguments :
Name | Type | Description |
---|---|---|
value | String | The value to escape |
Sample :
If you want to set in a JS variable a value incomming from the XML, you cannot affect it directly because if there is a " or a line return this would not be a valid javascript line.
<script type="text/javascript"> var name = "<xsl:value-of select="ametys:escapeJS(@name)"/>"; </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 | The name of the plugin hosting the file |
path | String | The path in the resource directory of the plugin |
Sample :
<script type="text/javascript" src="{ametys:pluginResourceURL('web', 'js/jquery.treeview.min.js')}"/>
Description :
Returns the current sitemap node. The page visible are the one visible by the user if access limitation is set.
The returned DOM is like :
<sitemap sitemap:site="www" sitemap:lang="fr"> <page sitemap:id="page://uniqueid" sitemap:name="index" sitemap:title="Accueil" sitemap:long-title="Accueil" sitemap:path="index"> <page .../> ... </page> ... </sitemap>
On a page tag, you can have the following attributes depending on the page type :
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"
On a page tag, you can have the following attributes, depending on the current page
sitemap:in-path="true" // if the page is in the breadcrumb (can be the current one) sitemap:current="true" // if the page is the current page
On a page tag, you will find the tags applied prefixed with PLUGIN_TAGS
sitemap:PLUGIN_TAGS_INVISIBLE="true" // if the page has the "invisible" tag
On a page tag, you will find any metadata of the page (except if its type is composite, binary or richtext and except if it is multiple)
Signature :
Node sitemap()
Sample :
<ul> <xsl:for-each select="ametys:sitemap()/page"> <li><xsl:value-of select="@sitemap:title"/></li> </xsl:for-each> </ul>
Description :
Returns the part of the sitemap node. The page visible are the one visible by the user if access limitation is set.
Signature :
String sitemap (String pageId)
Arguments :
Name | Type | Description |
---|---|---|
pageId | String | The id of the page |
<ul> <xsl:for-each select="ametys:sitemap('page://xxxxxx')/page"> <li><xsl:value-of select="@sitemap:title"/></li> </xsl:for-each> </ul>
See ametys:sitemap() method for more details.
Description :
Returns a DOM corresponding to the connected user.
This also allows to know if a user is connected.
Please not that this method should not be called in cachable environnement (cacheable service, content...)
The DOM returned is really dependant on the UsersManager your are using (LDAP, SQL, others...).
Here is a description of what you can receive from the StaticUsersManager (the one used for demo purpose with hard coded users) or from the JDBCUsersManager (the one with users stored in a sql database) :
<user login="USERLOGIN"> <firstname>FIRSTNAME</firstname> <lastname>LASTNAME</lastname> <email>EMAIL</email> </user>
Signature :
Node user()
Sample :
To know what you can receive in your conditions. Execute the following code and analyse the source code produced ON A LIMITED PAGE (to avoid cache purpose and to do not have empty result).
<MARKER><xsl:copy-of select="ametys:user()"/></MARKER>
Description :
Returns the value of a configuration parameter.
Signature :
String config(String id)
Arguments :
Name | Type | Description |
---|---|---|
id | String | The identifier of the parameter to get |
Sample :
<script type="text/javascript"> alert("You will receive an email from <xsl:value-of select="ametys:config('smtp.mail.from')"/>"); </script>
Description :
Returns the value of a site parameter.
Signature :
String siteParameter(String parameter)
Arguments :
Name | Type | Description |
---|---|---|
parameter | String | The identifier of the parameter to get |
Sample :
<script type="text/javascript"> var googleAnalyticsIdentifier = "<xsl:value-of select="ametys:siteParameter('site-param-google-web-property-id')"/>"; </script>
Description :
Returns the value of the parameter of the service currently rendered.
This should only be called in a service rendering.
You can optionnaly provide a default value.
Signature :
String serviceParameter (String parameter)
String serviceParamter (String parameter, String defaultValue)
Arguments :
Name | Type | Description |
---|---|---|
parameter | String | The identifier of the parameter to get in the current service |
Name | Type | Description |
---|---|---|
parameter | String | The identifier of the parameter to get in the current service |
defaultValue | String | If the value is not set, switch to this default value (this can happend when a new parameter is added, to be compatible with existing data). |
Description :
Returns the value of a request parameter.
Be carefull! This should only be used in non cachable xsl file (e.g. non cachable service). If not, the result of the first visitor will be used for every visitor...
Signature :
String requestParameter(String parameter)
Arguments :
Name | Type | Description |
---|---|---|
parameter | String | The identifier of the parameter to get |
Sample :
If you call the following url http://www.ametys.org/fr/index.html?id=3
<input type="hidden" name="id" value="{ametys:requestParameter('id')}"/>