Search in the Documentation:

Content templates in details

We said that when a content node other than a jnt:page is called, Jahia will look for a content-template corresponding to the node type. In that particular case, the main resource is the content node requested in the URL and the content templates defines how this particular node should be displayed. As a final HTML page still needs headers, footers and so on, a content-template builds the page around the main resource.

To create a content template, first right-click on the desired parent in the Selector (most of the time the “base” template) and fill-in the following form:

[image]

As a template it shares properties with other templates, but some are not used for content templates: view, we see later that the view will be set by the main resource display, and hidden from selection as it does not appears in a selector.

The content templates parameters are:

  • System name: it is the name of the template. As in the case of a page template, this name will be used to call the template from an URL. For example if you create two content templates for a news (/sites/site1/contents/news/news1.html) with tpl1 and tpl2 as system names, you will be able to display the news item by using:
  • /sites/site1/contents/news/news1.tpl1.html or /sites/site1/contents/news/news1.tpl2.html
  • Content template - apply on these nodes: this property defines the nodetypes for which this template will be used. The resolution will look for the nodetype of the node then the parent types until it finds (or not) one.
  • For example to create a specific content template for a jnt:news type, you will add jnt:news to the list of nodes on which to apply the content template. If you want a generic rendering for all contents, you can add the jnt:content nodetype as most of content objects have jnt:content as a parent type.
  • Content template – can be used as default: check this box if you want to use this template as the default template, meaning that when no template is specified, the template will be used to render the content.
  • Content template – priority: if multiple default templates match the template resolution (for example if you have a default template for jnt:content as well as for nt:base, both are parent type of most of contents) the highest priority one will be used to display the content.

To define where the main resource (the targeted node) must appear in the page, we use the component “main resource display” and drag it in the page.

[image]

When dragging this component in the page you can set the view that must be used for the content node and also enforce a CSS class or ID.

[image]

Main resource display is represented by a grey rectangle in the page. The name of the view is displayed in the center of the rectangle.

[image]

[image]

Interest of content-templates

The great thing about content templates is that it is very easy to add other components around the main resource that will be displayed along with it when a node of that type is requested.

Those components may be static information (a simple text component containing legal advice for instance) or dynamic ones that will adapt themselves depending on the values of the node.

If you think about our dog-academy web site, we can imagine that there is a content-template to display dogs’ portraits. You can for example add in this content template a Comments component, or a Rating component. Each time a visitor will consult a dog page, Jahia will automatically add a comment form, or a rating form that will be attached to that dog.

If a client wants to change the layout or the position of elements in the dog pages, or add a new component that will display the titles won by the dog in shows, one can just make the changes in the studio, add the missing component and redeploy the templates on the dog-academy web site.