Style selection
A theme's configuration file _config.json
associates templates with content types for a given theme and context. You can override these assignments using resource bundles.
Default style
The key _template
in a Styleguide data file assigns a template to the data file, as in the following example.
{ "_template": "/path/to/AuthorPage.hbs" }
Referring to the previous snippet, when a visitor retrieves an author's page, Brightspot looks up the template AuthorPage.hbs
, populates the placeholders with retrieved data, and returns the HTML code.
You can override the assignment between a data file and template using a resource bundle. The following example describes how to override the default template for an author's bio page.
Step 1: Determine the assigned template
Open the data file that contains template assignment you want to override.
Note the template specified by the key
_template
.
Referring to the snippet Assigning default ftyle, the assigned template is /path/to/AuthorPage.hbs
.
Step 2: Identify overriding templates
Create or locate the template you want to use as the default override.
Example 86. Original template (AuthorPage.hbs) {{#element "name"}} <h1>{{this}}</h1> {{/element}} | Example 87. Overriding template (AuthorPageNew.hbs) {{#element "name"}} <h1>{{this}}</h1> <h1>Writer Emeritus</h1> {{/element}} |
The snippet Overriding template (AuthorPageNew.hbs) adds a byline Writer Emeritus
under the author's name.
Step 3: Identify overriding data files
Create or locate the data files that use the template you identified in Step 2. For information about creating a data file, see Populating the Styleguide preview.
Step 4: Declare overriding template
Create or open a properties file as described in Creating properties files.
Add a line in the properties file similar to the following example:
/path/to/AuthorPage.hbs/defaultTemplate=/path/to/AuthorPageNew.hbs
In the previous snippet—
The left side of the assignment contains the template you determined from Step 1. The literal
/defaultTemplate
is mandatory.The right side of the assignment is the file you identified in Step 2.
Step 5: Register templates
Register the overriding template in the styles
member of the theme's configuration file _config.json
.
{ "styles": { "/core/author/AuthorPage.hbs": { 1 "example": "/author/AuthorPage.json", 2 "templates": [{ 3 "displayName": "Writer Emeritus", "template": "/core/author/AuthorPageNew.hbs" } ] } } }
Step 6: Rebuild and upgrade theme
Rebuild the theme and then install it as a new release. For details, see Upgrading a theme to new release.
![]() Figure 165. Author page with assigned template | ![]() Figure 166. Author page with overriding template |
Restricting available styles
The key styles
in a theme's configuration file _config.json
assigns available styles to a given template, as in the following example.
You can override the styles available to a given content type using a resource bundle. In most use cases, you limit the available styles declared in _config.json
. The following example describes how to limit the available styles for an author's bio page.
![]() Figure 167. Available templates from configuration file | ![]() Figure 168. Available templates from resources bundle |