Template models are container pages that you add to the sitemap via the sitemap editor. When you click on Create page, the available template models are shown in the tab "Container pages". When dragging a template model into the sitemap, the model is copied to create a new page. Typically, the template developer creates and configures model pages once having finished the template JSP and content type implementation, but before editing the website’s contents.
The concept of template models allows having some content already placed on new pages and you can even use them to decide if content should be copied to each new page or if the same content should be reused on each page.
We explain how to add new template models for your site and how to edit them.
Web pages usually have a common layout that should be altered only up to a certain level. Typically you may identify different kinds of pages that have lots of things in common. Template modelsTill OpenCms 9.0 known as model pages provide the "common parts" for pages of the same type. They contain all the content that should be present on all pages of a kind and can also contain elements an editor has to fill with specific content when creating a new page using the template model.
It's worthwhile noting the relation between template JSPs and template models. In OpenCms the "frame" of each web page is provided by a template JSP. It is your design decision if you provide only the HTML head and a big container in the body of your template JSP, or if you already define a more specific structure of your web pages in the template JSP. Templates are changed by changing the
template property for a web page. You should keep in mind: what's placed in the template JSP is common to all pages using the template. If you change the template JSP, all pages using the template will change.
In contrast, a template model is just a container page with some content in it, that is used as a master for new pages. Putting the layout into template models makes your design more flexible in the sense that you can provide a set of layout elements and a template developer who can edit template models. Thus new page layouts can be generated as in a modular construction system, without ever touching a JSP again. In contrast to the template JSP, changes in a template model do not necessarily change existing pages created from that model. If you drop content from the template model, it will still be present on all pages created by that model. If you add new content, it will not appear on existing pages created from that model and also property changes in the template model will not propagate to existing pages. Altering content may influence the copies, if the content is reused on the generated pages and not copied.
To create a new template model you can click on the sign on "Template models" or open the context menu of an existing template model to copy it. Once the template model is created, click its icon to edit it. You get a confirmation dialog before you can edit the page. It should guarantee you are aware of the implications of editing a model.
Editing a model is nearly exactly the same as editing any other container page. The only difference is a special element setting available for all elements on the pageExcept for element and inheritance groups.. If editing a template model, for each element you can decide if the element should be copied or reused if a page is created using the model. Therefore, click the gear wheel by the element to open the element settings. In the group "Template model options" the option "Copy this element" can be checked if the element should be copied. If the option is unchecked, the element will be reused.
When you add a new template model, the container page is created (in the current sitemap's subfolder
.content/.templates/) and configured as a model in the sitemap configuration. In this configuration file (
.content/.config under the sitemap's main folder) you have further configuration options, found under the tab "Templates". You can: