Template models are container pages that you add to the sitemap via the sitemap editor. Clicking 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 he has finished the template JSP and content type implementation, but before editing the website’s contents.

The concept of template models allows to have some contents already placed on new pages and even to decide if a 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 contents 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.

1.1 Template JSP vs. template model

Its worth to make a note on 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 on it, that is used as 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 of a template model not necessarily change already existing pages created from the model. If you drop a content from the template model, it will still be present on all pages created by the model. If you add a new content, it will not appear on existing pages created by the model and also property changes at the template model will not propagate to existing pages. Altering contents 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 it's 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 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. Therefor, click the gear wheel at 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

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 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 "Model pages". You can:

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