Content types


  1. Default content types
    1. Article
    2. News
    3. Multimedia gallery
    4. Photo gallery
  2. Default views (=metadataSet)
    1. View "main"
    2. View "abstract"
    3. View "link"
  3. Available content types for the contributor
  4. Content type render
    1. How to use a helper
    2. resolver
      1. Sample
    3. page
      1. Sample
    4. tags
      1. Sample

Default content types

Article

The default content type "Article" is composed by :

  • a title
  • a sub-title
  • an illustration
  • an abstract
  • a rich text
  • a contact :
    • contact name
    • contact email
  • seo data
    • subject
    • description
    • keywords

News

The default content type "News" is composed by :

  • a title
  • a sub-title
  • an illustration
  • start date and end date of the event
  • an abstract
  • a rich text
  • a contact :
    • contact name
    • contact email
  • seo data
    • subject
    • description
    • keywords

Multimedia gallery

TODO

Photo gallery

TODO

Default views (=metadataSet)

Each declared content must have at least 3 views :

View "main"

This is the complete view. The content is displayed with its all data (except its metadata like seo data)

View "abstract"

This is the reduce view of the content. This view is composed by the title, the abstract, the illustration and a link to the complete content.

This view can be used to list the news on home page for example.

View "link"

This view can be used in a result search. It display only the title of the content and a link to the complete content.

Available content types for the contributor

Since 3.1 version, the list of availables content types can depend on :

  • the type of site (See. Type of site )
  • the type of site and the skin
  • the type of site, the skin and the page template
  • the site type, and the zones of a skin's templates (from 3.4 version only)

The list of availables content types are defined in files named content-types-[siteType].xml.

There are two modes :

  • include : to accept only the content types listed in file. This is the default mode
<?xml version="1.0" encoding="UTF-8"?>

<content-types mode="include">
      <content-type id="org.ametys.web.default.Content.article"/>
      <content-type id="org.ametys.plugins.news.Content.news"/>
      <content-type id="org.ametys.plugins.multimedia.Content.photosGallery"/>
      <content-type id="org.ametys.plugins.multimedia.Content.multimediaGallery"/>
</content-types>
  • exclude: to accept all content types except those listed in file
<?xml version="1.0" encoding="UTF-8"?>

<content-types mode="exclude">
      <content-type id="org.ametys.plugins.newsletter.Content.newsletter"/>
</content-types>

This type of files can be defined in three location :

  • in your skins/[skinName]/template/[templateName]/conf directory. If present, this file will be used to list the available content types for pages on which this template is assigned, and for each zone of the page (from 3.4 version only).
  • in your skins/[skinName]/conf directory : if presents this file will be used to list the available content types for your skin
  • in your WEB-INF/params directory : if presents this file will be used to list the available content types for your type of site

The structure of the files is different in the first case and in the two others. The global configuration file and the skin configuration file use the simple structure shown above, a simple list of content type IDs.

To define the templates and zones, the file (placed in the template's conf directory) must follow this structure:

<?xml version="1.0" encoding="UTF-8"?>
<content-types>
    <!-- Available content types for the template. -->
    <template mode="exclude">
        <content-type id="org.ametys.plugins.newsletter.Content.newsletter"/>
    </template>
    <!-- Available content types for each zone. -->
    <zones>
        <zone id="default" mode="exclude">
            <content-type id="org.ametys.plugins.news.Content.news"/>
        </zone>
        <zone id="right-column" mode="include">
            <content-type id="org.ametys.web.default.Content.article"/>
            <content-type id="org.ametys.plugins.news.Content.news"/>
        </zone>
        <zone id="media-gallery" mode="include">
            <content-type id="org.ametys.plugins.multimedia.Content.photosGallery"/>
            <content-type id="org.ametys.plugins.multimedia.Content.multimediaGallery"/>
        </zone>
    </zones>
</content-types>

N.B: the "template" section and the "zones" section are not mandatory, but one at least must be specified.
N.B.2: in the same way, all zones are not required to be specified in the "zones" section. Existing zones not mentioned in the file have the same available content types as their template.

Content type render

The content type render is a XSL file.
You can have a XSL file per view (or metadataset).
You can override views of default content types. Override the content rendering

When you write such a xsl you have the following variables :

Variable name

Description

$back-office

Have the following values
'' or 'back' if the user is in the backoffice
'preview' if the user is previewing
'front' on the front.

e.g. when you set statistics on your site, you only wants to have it on the front site, you will the surround it with <xsl:if test="$back-office = 'front'">

$contextPath

The context path. All url have to be prefixed by the context path, but some other variables already includes it (prefix or raw-context)

$pluginName

The name of the plugin declaring the content type. Usefull for resources. <img src="{$contextPath}/plugins/{$pluginName}/resources/img/myimg.png"/>

$siteName

The name of the current site

$prefix

The url prefix for link to pages. <a href="{$prefix}/{$lang}/index.html">

$raw-context

The browser context for links that depends on the preview state, but that are not pages. This is a very limited use, but this is manly to load plugins urls (for rss for examples).
e.g.
<a href="{$contextPath}/plugin/myplugin.html"> from backoffice and preview will return non validated contents, from frontoffice will return validated contents.
<a href="{$raw-context}/plugin/myplugin.html">, from backoffice will return validated contents, from preview and frontoffice will return validated contents.

$lang

The current language. e.g. 'fr', 'en'...

$skin

The current skin name. Usefull to look for resources into the current skin. e.g. <img src="{$contextPath}/{$skin}/resources/img/myimage.png"/>

 

You also have the following xslt helpers:

How to use a helper

If the helper is named "helper" and its class name is "org.ametys.cms.transformation.xslt.MyHelperComponent", add the helper prefix to your xsl header:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
			      xmlns:helper="org.ametys.cms.transformation.xslt.MyHelperComponent"
                              exclude-result-prefixes="helper">
...
</xsl:stylesheet>

The at anytime you can enter xsl instruction, use the name + ':' + the method name + ( + arguments comma-separated + ).
e.g.

    <xsl:value-of select="helper:myHelperMethod('myarg')"/>

resolver

To resolve links.

Name

Namespace

resolver

org.ametys.cms.transformation.xslt.ResolveURIComponent

Method

Arguments

Description

resolve

String type
String uri
boolean download (false by default)

This method transforms an uri to an url (depending on its type). 
The list of available values for 'type' depends on your plugin. The defaults are :

  • type "page", the uri is a page id
  • type "attachment-content", the uri is a resources id to a file attached to a content.
  • type "local", the uri is the id of a file attached to a richtext
  • type "metadata", the uri is the name of a metadata containing a file (with optionnaly the content id as a request parameter named contentId)
  • type "explorer", the uri is the id of a file in the resources explorerThe value of uri depends on the type.
    If you want a link to download a file instead of opening it in the browser, set download to true. The basic sample is for pdf or images files that will open in the browser if you set to false.

resolveImage

String type
String uri
int height
int width
boolean download (false by default)

This method transform an uri to an url (depending on its type) as above, but limited to images files, because image will be resized according to one or both fixed sizes.

type: see above.
uri: see above.
height: the desired height or 0 to keep ratio.
width: the desired width or 0 to keep ratio.
download: see above.

For width and height, you :

  • specify both to have a image of this exact size : ratio of the image will not be guaranted.
  • specify only one (the other is '0') : this size will be guaranted, and the other size is free to keep ratio aspect.
  • specify none (both are '0') : do the same as the 'resolve' method.

resolveBoundedImage

String type
String uri
int maxHeight
int maxWidth
boolean download (false by default)

This method transform an uri to an url (depending on its type) as above, but limited to images files, because image will be resized to fit into a given size.

type: see above.
uri: see above.
maxHeight: the desired maximum height for the image.
maxWwidth: the desired maximum width for the image.
download: see above.

Add the following prefix to your xsl header xmlns:resolver="org.ametys.cms.transformation.xslt.ResolveURIComponent"

Sample

This sample is extracted from the article xsl file.
This part of the file, creates the image tag relative to the illustration.

The illustration is stored as a composite metadata : the image itself (of type file) and its alternative text (of type string).
Type 'file' for metadata store the 2 information you need : the type of link and the uri.

Finally, we resolve the url of the image. In this case we know that the image will not be larger or higher than 150 pixels.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:resolver="org.ametys.cms.transformation.xslt.ResolveURIComponent"
                exclude-result-prefixes="resolver">

    ...
        <!-- test if metadata is set -->
        <xsl:if test="metadata/illustration/image">
           <img src="{resolver:resolveBoundedImage(metadata/illustration/image/@type, metadata/illustration/image/@path, 150, 150)}" alt="{metadata/illustration/alt-text}"/>
        </xsl:if>
    ...

<xsl:stylesheet>

page

To get information from a page

Name

Namespace

page

org.ametys.web.transformation.xslt.PageComponent

Method

Arguments

Description

getTitle

String pageId

or

String sitename
String lang
String path

Returns the title of a page

pageId : the id of the page.

sitename : the name of the site.
lang : the language code
path : the path of the page in the lang and in the site

getLongTitle

String pageId

or

String sitename
String lang
String path

Returns the long title of a page.
This will never be empty, because event if it is not filled, it will at least returns the short title

pageId : see above.

sitename: see above.
lang: see above.
path: see above.

getMetadata

String pageId
String metadataName 

or

String sitename
String lang
String path
String metadataName

Returns (as a string) the value of the metadata of a page.
If the metadata has a problem, will returns empty.

pageId : see above.
metadataName : The name of the metadata. Can be / separated for composite metadatas.

sitename: see above.
lang: see above.
path: see above.

Sample

Suppose you have a metadata that is a page reference, declared as below in your content type.

<cms:metadata name="name" type="string">
     <label>Nom</label>
     <description>Description</description>
     <widget>sitemap</widget>
</cms:metadata>

When you render it you want to make a link to this page: (see above for 'resolver')

    <a href="{resolver:resolve('page', string(name), false())}">...</a>

BUT you want to have the page title as the text of the link, do the following:

    <a href="{resolver:resolve('page', string(name), false())}"><xsl:value-of select="page:getTitle(name)"/></a>

for this to work, you have to declare both 'resolver' and 'page'

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:resolver="org.ametys.cms.transformation.xslt.ResolveURIComponent"
        xmlns:page="org.ametys.web.transformation.xslt.PageComponent"
        exclude-result-prefixes="resolver page">

tags

To get information on a tag

Name

Namespace

tags

org.ametys.web.transformation.xslt.TagsComponent

Method

Arguments

Description

getLabel

String siteName
String tagName
String lang

Get the readable label of a tag having its key (or name)

siteName : the name of the site.
tagName : the key.
lang : the lang code ('fr', 'en').

getDescription

String siteName
String tagName
String lang

Get the readable description of a tag having its key (or name)
Since Ametys 3.1.1
siteName : the name of the site.
tagName : the key.
lang : the lang code ('fr', 'en').

getCategory

String siteName
String tagName

Get the id of a category of a tag. This method can helps you to know between all tags affected to a content or a page, which ones are part of a given category.

siteName : the name of the site.
tagName : the key.

Sample

This sample displays the name of the tags that are part of a thematic category.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:tags="org.ametys.web.transformation.xslt.TagsComponent"
        exclude-result-prefixes="tags">

  <xsl:param name="siteName"/>
  <xsl:param name="lang"/>

  ...
  <xsl:for-each select="tags/*">
      <xsl:variable name="tagKey" select="local-name(.)"/>

      <xsl:if test="tags.getCategory($siteName, $tagKey) = 'THEMATICS'">
          <xsl:value-of select="tags:getLabel($siteName, $lang, $tagKey)"/>
      </xsl:if>
  </xsl:for-each>
  ...

</xsl:stylesheet>
Back to top