Search code examples
magnolia

How do I migrate templates to a new subdirectory?


When I created my light module, it was only intended to provide templates for a blog:

templates/
├── components/
└── pages/
    ├── blogArticle.yaml
    ├── blogCategory.yaml
    ├── blogIndex.yaml
    └── blogSearch.yaml

However, now I want to add additional templates (e.g. one-off marketing pages). In order to keep my light module organized I would like to move my blog templates into a "blog" subdirectory:

templates/
├── components/
└── pages/
    └── blog/
        ├── article.yaml
        ├── category.yaml
        ├── index.yaml
        └── search.yaml

If I simply move the templates into a new "blog" subdirectory, I will get an "Unknown Template" page error and will break my blog. This is because pages reference templates by their path:

mgnl:template -> example-light-module:pages/blogIndex

How do I migrate the templates to a new subdirectory without breaking the existing blog?


Solution

  • The following steps should provide you with a good process:

    Step 1: Duplicate and Deprecate the Templates

    Duplicate the current templates and move them into a new "blog" subdirectory.

    Deprecate the current templates by:

    1. Prepending the word "DEPRECATED" to the template definition titles
    2. Setting visible to false in the template definitions

    For example:

    title: DEPRECATED - Blog Article
    description: Template for a single blog article.
    renderType: site
    visible: false
    

    Step 2: Reassign and Publish the Pages

    1. Deploy the duplicated templates and the deprecation changes.
    2. Assign the duplicated templates to the blog pages and publish the changes.
    3. Once the pages have been successfully switched to the new templates, delete the deprecated templates.