I am looking to set frontmatter variables to a default value for a particular layout.
My understanding is that the normal way to do this is to have an architype file that stores the defaults for the frontmatter. Then when I create a new page, hugo will use those as the defaults.
My issue is;
What if I want to change the defaults for all markdown files in a directory or layout at once? or…
If I want to leave the frontmatter parameter empty, how can I set it according to defaults somehow?
I’m not 100% I understand your question. Do you want to create a different archetype for a particular section/directory of your site, so that new posts will have different frontmatter? Or do you want to do a mass update/change of frontmatter for already existing posts?
Hi funkydan, thank you for asking further clarification.
Do a mass update/change of frontmatter for existing posts? No.
Create a different archetype for a particular directory of my site? Yes, well sort of…but without the archetype…
Perhaps the best way to phrase what I want is: How do I set default values for frontmatter if they are not set or omitted from the markdown file?
Here is an example of what I want to do;
For a section of my website, I display a comment form at the bottom of the text. Most of the time I want to show it, sometimes I don’t. So I want to default it to always show it, unless I specifically set the frontmatter value to true.
I know I can just set that in my layout folder were I do isset(myparameter) etc…but I was just wondering if there is a more proper or common practice way to do it?
I can’t think of any problems with the way you’re thinking.
Since the front matter is a boolean value, if it’s not present, then checking for the value will return false… like with draft posts. If draft=falseor it’s not set, then the post is published, but if draft=true then it isn’t published (unless you run with the -d flag).
I suppose I shall go forth an do it that way…which now that I think about it a bit more clearly, seems ok…
I think I was initially confused about what architypes were for. I thought they were the way to set things default. But now I know they are just for creating new content with the preset frontmatter…and that is their only purpose (that I know of)
Thank you once again, everyone here is so helpful, hope I can repay…
John
Yeah that’s the way I’ve ended up going…I sort of just wondered if there was another way…but I think I was just initially confused with architypes and what their use was for…so perhaps in retrospect this was a silly question
One of the things I love about this forum is the many different ways you can do things with hugo, no matter how silly it may seem you always learn something new.