---
agentTools:
  projectIndex: https://opencontent.readme.io/v3.5/llms.txt
---

# Template Settings

Open Content Template Settings

[block:api-header]
{
  "title": "About Template settings in Open Content"
}
[/block]

Some times you want a setting for a template, that can be set outside the normal Edit screen.
This can be used to add options to a Template, anything from color variations to a switch to change the rendering of the template layout.
When you add a setting to a template, the user will first be presented with an "Edit Template Settings" screen after choosing a template and before the content can be edited.

You can use all the Field types for Template settings, making Open Content templates even more flexible.

[block:api-header]
{
  "title": "Adding Template settings in Open Content"
}
[/block]

Template settings can be defined by adding the "\[name]-schema.json" and "\[name]-options.json" files.
In these files you define the fields as you would for a regular template, but they will appear as settings.
For a single item template \[name] should be equal to the name of your template file; "name.hbs" or "name.cshtml".
For a Multi-item template,  \[name] will be read from the manifest.json file.

In the following multi item manifest example \[name] would be "list" and not the name of the template file ("overview").
So you would name the template settings files: "list-schema.json" and "list-options.json".
In case of a multi item template the template settings are valid for the combined list + detail template.

[block:code]
{
  "codes": [
    {
      "code": "{\n\t\"templates\": {\n\t\t\"list\": {\n\t\t\t\"type\": \"multiple\",\n\t\t\t\"title\": \"Overview\",            \n\t\t\t\"main\": {\n\t\t\t\t\"template\": \"overview.hbs\",\n\t\t\t},\n\t\t\t\"detail\": {\n\t\t\t\t\"template\": \"detail.hbs\",\n\t\t\t}\n\t\t}\n\t}\n}",
      "language": "json",
      "name": "manifest.json"
    }
  ]
}
[/block]

[block:api-header]
{
  "title": "Using template settings in your Template"
}
[/block]

You can use settings in your Handlebars templates using @root.Settings.MySetting.
Below is an example of a Template with a list of link, with a Template wide setting to open the links in a new window

[block:code]
{
  "codes": [
    {
      "code": "{{#each Items}}\n<a href=\"{{Link}}\"{{#if @root.Settings.NewWindow}} target=\"_blank\"{{/if}}>{{Text}}</a>\n{{/each}}",
      "language": "handlebars",
      "name": "List.hbs"
    },
    {
      "code": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \t\"NewWindow\": {\n\t\t\t\"title\": \"Open Links in new Window\",\n\t\t\t\"type\":\"boolean\"\n\t\t}\n  }\n}",
      "language": "json",
      "name": "List-schema.json"
    }
  ]
}
[/block]