6.3.10. Dynamic Templating

Requirements

In order to quickly implement microsites, campaigns, or specialized channels with unique template requirements, templates can be updated without interrupting the service or requiring a redeployment of the application.

Solution

Views can be implemented as FreeMarker templates and uploaded to the Content Repository in a container file, preferably a JAR. For details, consult the "Loading Templates from the Content Repository" chapter in the [CAE Developer Manual].

Create the archive containing the templates

A template set archive, preferably a JAR file, can contain FreeMarker templates which must be located under the path: /META-INF/resources/WEB-INF/templates/siteName/packageName/

The easiest way to create the JAR is to create a new Maven module with a POM like this one:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example.groupId</groupId>
  <artifactId>templates</artifactId>
  <version>--insert version here--</version>
  <packaging>jar</packaging>
  <description>
    CAE templates to be uploaded to a CMTemplateSet document in
    /Themes/*my.package*/templates/ with name *my.package*-templates.jar.

    Use the *my.package* as a reference in a Page's
    "viewRepositoryNames" settings (list of strings).
  </description>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <archive>
            <addMavenDescriptor>true</addMavenDescriptor>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Put your templates below the path src/main/resources/META-INF/resources/WEB-INF/templates/--themeName--/--packageName--/, for example src/main/resources/META-INF/resources/WEB-INF/templates/corporate/com.coremedia.blueprint.common.contentbeans/Page.ftl

Upload the template set

CoreMedia Blueprint provides the content type Template Set (CMTemplateSet) which is used for this purpose. Create a document of type Template Set in folder /Themes/--themeName--/templates and upload the JAR to its archive property. Its name is significant and is used to reference template sets from channel settings, as explained see below.

NameDescription
description A description of the purpose / contents of the code.
archive blob property that contains the archive (preferably a JAR) that contains the templates.

Table 6.14. Properties of CMTemplateSet


Add the template set to a page

A Page context can be configured to add additional template sets to all pages rendered in its context. The names of additional template sets are configured in a string list setting viewRepositoryNames of a Page. Like all settings, a Page will inherit this list of names form its parent context, if it is not set. See Section 6.3.11, “View Repositories” for more details.

[Note]Note

The CAE will resolve view repository names automatically according to the predefined name pattern. For instance, if a Page sets its viewRepositoryNames to the list ["christmas", "campaigns"], each page rendered in this context will use templates implemented in the Template Sets /Themes/christmas/templates/christmas-templates.jar and /Themes/campaigns/templates/campaigns-templates.jar before falling back to the default templates defined for the web application.