Search the documentation
 Show GitHub edit links  Hide GitHub edit links
In OpenCms since: 9.5 Documented since: 9.5 Latest revision for: 9.5 Valid for OpenCms: 10.5.3

Template models are container pages that you add to the sitemap via the sitemap editor. When you click on searchBigIconActive 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.

The idea of template models

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.

Template JSP vs. 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.

Creating and editing template models

Template models are created via the sitemap editor's "Templates" view. Open the sitemap editor, click "Select view" and choose "Templates". You get the following view.

Template models are created in a sitemap and are available only in this sitemap and (in the default configuration) also in sub-sitemaps. So, if you create a template model, make sure to be in the correct sitemap.
Fig. [sitemapeditor_templatesview]: The templates view of the sitemap editor

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.

Fig. [templatemodels_elementsettings]: Special element settings for template models
Since OpenCms 10.5 the "Copy this element" setting is available on every container page. Since OpenCms 10.5 adds a "Copy page" feature for container pages, every page can act like a template model.

Further configuration for template models

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:

  • disable all template models configured in parent sitemaps.
  • set a model that is used as the default if a page is created without explicitly choosing a model
  • select a single template model as disabled (which makes sense in particular if the model is enabled in a parent sitemap)
Fig. [sitemapconfig_templatemodels]: Configuring template models in the sitemap configuration

You can improve this page

Please contribute your suggestions or comments regarding this topic on our wiki. For support questions, please use the OpenCms mailing list or go for professional support.