Content Template
A content template, in Jahia, defines the layout that displays as a full page a content item that is not a regular page. A job offer, a product sheet or a news item thus gets its own page without anyone creating that page in the site tree. For a team managing hundreds or thousands of items, pages are produced automatically instead of being created one by one.
Definition and how it works
An item shown on its own page is called a main resource. A content template is associated with a content type, so by default an item of that type, when it can be shown on its own page, is displayed with it, unless another template has priority or is requested in the URL. In a Java module, a main resource display component placed in the template calls a view (the display code) on the requested item, and several can sit in one template, for example the history and comparison views.
In a Java module, templates are created in the Studio, the developers’ tool. In a JavaScript module, they are written directly in code (JSX). Templates inherit from one another, so a content template can reuse the header, navigation and footer of a base template. Permissions can restrict their use to certain people.
Academy documentation: rendering content
Related terms: View · Content Type · Content item · Template
Resources that cover this term
- How Integrators Can Design the Ultimate Content Author Experience in a CMS? (Integrators Tips Pt.1)
- How to develop a DXP platform with the best UX for business users?
- Jahia DX and AMP smoothly match!
- Customer Data Platforms (CDPs): a practical guide to a unified customer experience
- What is a dynamic website?
- iPhone 5 for developers and content providers
Content template vs page template: the differences
A content template differs from a page template (which the contributor picks when creating a page) and from a view (which renders only one content item).
| Term | How it differs |
|---|---|
| Page template | A page template is for pages in the site tree: the contributor picks it when creating the page, then fills its areas. A content template applies automatically to every item of a type. |
| View | A view renders a content item as HTML wherever it is displayed. A content template builds the full page around that item, with the header, navigation and other areas. |
| Content type | The content type defines the item’s structure. The content template, associated with that type, defines how its items are displayed as full pages. |
Content template in practice
A careers site publishes several hundred job offers a year. Recruiters enter them in a content folder, a list on the "Open positions" page displays them and a click opens each offer as a full page, thanks to the content template associated with the "Job offer" type. No page is created or deleted by hand.
Each offer’s address derives from its path in the repository unless a vanity URL is set, which is worth agreeing with the SEO team.
Frequently asked questions
Do we need to create one page per job offer or product in Jahia?
A content template exists precisely to avoid creating pages one by one. With a template associated with the "Job offer" or "Product" type, by default, an item of that type that can be shown on its own page is displayed as a full page automatically. Contributors normally manage the content only, stored in folders for example. This approach avoids thousands of pages to create, move and delete. It also keeps the presentation of all items consistent.
Where and by whom are content templates created?
Content templates are created by developers, in the Jahia Studio for a Java module or directly in code (JSX) for a JavaScript module. Templates are delivered with the rest of the project. Contributors normally work on the content the template displays, not on the template itself. Permissions can also restrict certain templates to specific people.
Can two content types each have their own full-page layout?
Yes, since a content template is associated with a content type. Job offers can have their layout and news items theirs, while reusing the header, navigation and footer of the same base template, since templates inherit from one another. In a Java module, a content template can have a view of its own or place one or more main resource display components, each of which calls a view on the item.