Rendering

There are various methods to change the visual appearance of a publication made up of common features without having to create an entirely new publication. These should all be called on the local Publication as registered in the Publication Definition or publication as provided by a feature or via the context object.

function registerReplaceableTemplate(code, templateName)

Registers a replaceable template in the publication.

This is a relation from an API code to a template, allowing for templates to be defined in a single place and used across the publication, reducing duplication and improving consistency. This allows you to set up default displays for a layout (e.g. pageParts, common UI elements) and then modify the display with application specific customisations.

Arguments:

code API code style code for the template
templateName The path to the template from the current publication’s template folder

Example usage:

P.webPublication.registerReplaceableTemplate("example:replaceable-templates:ui:button", "ui/button");

function replaceTemplate(code, templateName)

Replaces the template for the given code in the publication.

Key points:

  • replaceTemplate() will be called from the implementing plugin for the publication and not the plugin in which the template is replaced. Templates, therefore, are not suitable for replacement by usage of a feature which is defined outside of the publication registering plugin.
  • The same view is passed to a template that has been replaced so the view paths in the replaced template will need to match the original.

Arguments:

code API code style code for the template
templateName The path to the template from the current publication’s template folder

Example usage:

Publication.replaceTemplate("example:replaceable-templates:ui:button", "replaceable/ui/super-button");

function getReplaceableTemplate(code)

Returns the template for the given code. Useful for rendering common functionality (e.g. pageParts, common UI elements) with a replaceable template, which makes it easier to modify the visual appearance without altering the underlying functionality.

Arguments:

code API code style code for the template

Example usage to allow the searchResultRendererForTypes to have its template replaced with an application specific version without the need for any functionality changes:

publication.searchResultRendererForTypes(
    publication.DEFAULT,
    function(object, context) {
        var template = context.publication.getReplaceableTemplate("example:publication-common:search-result:default");
        return template.deferredRender({object:object});
    }
);