Can’t create custom template in Mercury theme
-
March 29, 2021 at 10:56 pm #5473[anonymous]
There’s a guide: https://getpublii.com/dev/how-to-create-custom-templates/
I’m using Mercury theme
- 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
- 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.
March 30, 2021 at 1:38 am #5474[anonymous]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.
March 30, 2021 at 5:23 am #5475BobI 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.
March 30, 2021 at 5:14 pm #5481[anonymous]Thank you all, it worked.
[anonymous] wrote: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
March 30, 2021 at 6:19 pm #5487[anonymous]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.
March 30, 2021 at 6:32 pm #5489[anonymous]Thank you, it is working now, seems like restarting app doing the trick too