Homepage

Module Templates

Last edit: Oct 26, 2022

With module templates, you can configure modules before deploying them to an environment. For example, you can specify the slug for a page (where the page will be available after the module is installed) upon installing the module.

Configuration

Values for variables have to be provided in the template-values.json file placed at the toplevel of the module:

modules
└──admincms
    ├── template-values.json
    ├── private
    │   └── graphql
    │       ├── get_customizations.graphql
    │       └── get_pages.graphql
    └── public
        └── views
            └── pages
                └── admin.liquid

Adding templates to module code

Templates work both in deploy mode (with the pos-cli deploy command) and in sync mode (with the pos-cli sync command). When the template-values.json file is present, the pos-cli finds it and applies the values in it to the templates. It then sends the output to the server with the resulting file filled in based on the templates.

In both deploy and sync mode, adding templates to module code works the same way. If you have sync mode running and you change the template-values.json file and then change one of the files using the template, they get processed and the latest version gets uploaded.

Markup

Everything between <%= and =%> is interpreted as a key to be found in the template configuration file. There is no logic supported, the only available filter is &, which unescapes the value provided by the user (by default they are all escaped).

Example

If you have a page with this code:

---
slug: <%= &slug =%>
layout: modules/contact_form/main
---

<h1><%= title =%></h1>

And a toplevel template-values.json with:

{
  "slug": "contact_form",
  "title": "Contact Page title"
}

During deploy or sync it will get filled in and sent to the server as:

---
slug: contact_form
layout: modules/contact_form/main
---

<h1>Contact Page title</h1>

Questions?

We are always happy to help with any questions you may have.

contact us