Sign in

Can’t create custom template in Mercury theme

  • This topic has 5 replies, 3 voices, and was last updated 3 weeks, 2 days ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5473
    endingmirage

    There’s a guide: https://getpublii.com/dev/how-to-create-custom-templates/

    I’m using Mercury theme

    1. Create a post-TEMPLATE_SLUG.hbs file

    Going to /themes/mercury-override/

    Creating post-CUSTOM_INDEX.hbs file with code from index.hbs since I want to make a custom template for index page

    1. In the theme’s config.json file, please add the following entry:
    "postTemplates": {
       "TEMPLATE_SLUG": "Human readable template name"
    }

    Creating a copy of config.json from /themes/mercury in /themes/mercury-override

    In that file I’m adding in the end of the file required code as this:

       
            {
                "label": "Drop cap",
                "cssClasses": "dropcap",
                "selector": "p"
            }
        ]
        "postTemplates": {
       "CUSTOM_INDEX": "Custom Index"
    }
    }

    Saving file. Going to Posts section, choosing any post, going into Post settings → Other options

    Post template: Not available in your theme

    Ok, what am I doing wrong here? If I restart Publii app, not only there are no post templates available, but all other options are gone. To fix this, I need to undo all my changes, delete all created files. I don’t get it. I tried doing this in /themes/mercury got same results. Tried to paste only required code in config.json, same results.

    #5474
    shaun2k

    Hi,

    1) Creating your custom post template in Publii/sites/your_site/input/themes/mercury-override/post-custom_index.hbs

    2) In your Publii/sites/your_site/input/themes/mercury-override/config.json

    Insert the “postTemplates” after the “supportedFeatures” block like so:

    "supportedFeatures": {
      "blockEditor": true,
      "tagsList": true,
      "tagImages": true,
      "authorImages": false,
      "searchPage": true,
      "errorPage": true
    },
      "postTemplates": {
      "custom_index": "Custom Index"
    },
    "config": [
      {
        "name": "postsPerPage",
        "label": "Posts per page",
        "value": 11,
        "type": "number"
      },

    You should see “Custom Index” available in the Post settings → Other options.

    Hope this helps.

     

     

    #5475
    Bob

    I will just add, that the custom templates are dedicated to posts, author, and tag pages only. If you want to override the index.hbs, just copy it to the override folder and modify as needed.

    --
    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!

    #5481
    endingmirage

    Thank you all, it worked.

    I will just add, that the custom templates are dedicated to posts, author, and tag pages only. If you want to override the index.hbs, just copy it to the override folder and modify as needed.

    Well, I can do that, and I did, for some changes. But I need to be able to create a frontpage in Editor, so I can edit it easily. Maybe I miss something again…

    Another question: I would like to add another post template, adding in config.json:

        },
        "supportedFeatures": {
            "blockEditor": true,
            "tagsList": true,
            "tagImages": true,
            "authorImages": false,
            "searchPage": true,
            "errorPage": true
        },
          "postTemplates": {
      "custom_index": "Custom Index",
      "custom_post": "Custom post"
    },

    And creating a file post-custom_post.hbs, and template Custom post in Post options don’t shows up again, am I missing something in syntax again? I’m sorry for these newbie questions

    #5487
    shaun2k

    endingmirage wrote:

    And creating a file post-custom_post.hbs, and template Custom post in Post options don’t shows up again, am I missing something in syntax again? I’m sorry for these newbie questions

    If you hadn’t reload the site after making the changes to config.json, the Theme Custom settings won’t be updated yet.

    What I normally do is to switch to a different site (assuming you have created more than one site), then switch back again to the original one you were working on. That way, it forces Publii to load the modified config.json and updates with the changes you’ve made.

    #5489
    endingmirage

    Thank you, it is working now, seems like restarting app doing the trick too

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.