Forum
Using alternative blog templates
Sorry - I've looked around for this, but can't find any documentation.
We've now got sections, and I think I heard it mentioned during one of the podcasts (it may have been a dream on a hot sleepless night) that you could use a different blog template for different sections. That's what I want to do, with one section currently for topical features, and another to be used for job listings. I've created a job post template and put it into the 'posts' folder, but can't see how to use this. When creating a new post I don't get given a choice. How does this work?
Thanks
I've never done that before but found this in the docs
Docs
Sorry if it's not what you was looking for
Thanks for the reply - I did see the page on perch_blog_sections but it seemed to be a way of listing sections rather than attributing templates to specific sections - and the example you've given above is pointing to a template to handle the listing of sections. Else I'm not clear where you would even use that line of code!
HI,
Not sure if this is what you are after, but you could try creating a different page template listing and detail page for each blog section, then use perch_blog_custom to set the list and detail template. Example from a list page below:
Thanks for the answer, but I'm still not getting it. These are all listing functions. When I create a blog post via the Perch admin, I don't get the option to use anything other than the default template, even though I've created one. I don't see how the above would change that.
This must be simple surely - what's the point of being able to create different blog templates if you can't select one to use?
Does
Work? I know it works for tags
No - I appreciate the offers of help, but I think on this occasion I need a Drew or Rachel answer. Thanks for trying - probably just my inability to frame the question properly.
I think by default Perch looks in templates folder, if no template exists it uses the default post.html in the app folder, have you created your own blog folder in the Perch templates folder?
\perch\templates\blog
If so by default Perch will use post.html, but I believe you can add alternate ones to the posts folder. There is a read me file in there that states.
"This folder can contain alternative post templates. They should be alternatives to post.html."
I haven't done it myself but I imagine if you create alternate page templates for each section and you add a perch_blog_custom, and set the template to this alternate template. Then when you add posts in the CMS it will use your alternate template.
Thanks Lee. As I put in my original question, I created a template and put it into the posts folder.
But the aim isn't, as you've detailed above, simply to use a different template as an alternative default - but to use a different template for each section. So when I get to create a new blog post, I only get to choose which section it belongs to AFTER it has handed me the default template. And when you create sections, the only things you can set are section name and an image - it would have made sense to be able to choose a default template at that point, but that isn't offered.
Apologies Mallen, I think I may have misunderstood your requirements. Like you say might be one for Drew and Rachel :-)
I've got this logged as an enhancement request. At the moment you can't set a default post template per section, but it's an obvious thing to add.
Drew - thanks for that. In the mean time, how do I select which template to use on a post by post basis? I thought that once I'd added a second template in addition to the default post.html then something would appear when I go to add a post that would ask which template to use. That doesn't seem to happen so I'm sure I'm missing something simple.
Yes, once you've added a second post template, a select box appears on the edit form.
OK - I've think I've been labouring under an illusion! My intention was to have different custom fields on different blog posts - so the one for the jobs section would have fields that weren't on the other content. But I'm seeing now that's not how it works. Basically you define your fields for your post - and then all the templates do is to change the way these fields are presented.
I imagined that I would go to add a post, choose the jobs template, get the fields that I'd created on that template.
Instead the process is add a post, get the fields on the default post template, select an alternative template that will format those fields. Hence my confusion (although it would be useful if the documentation mentioned how this works).
I will need to think through how I'm going to get this to work as it's a bit of a pain if lots of redundant fields are being presented to editors depending on which type of post they're creating. Hmm.
No, you can have different fields as you were expecting. The post template is used for both editing and output.
OK - so as I get it (and having seen a similar discussion now in a former forum entry) I have to create the post first using fields from the default template - then save with the other template selected, and then the edit screen will switch over to the new fields.
I can use that as a work around for now, but I don't think I could ask a client to work with that process. It would definitely be a useful feature to select the template before opening / on opening. Opening in one, saving, then getting the other is not ideal.
However it ends up, it does need documenting as well - I couldn't find anything that describes how this works. Thanks for the help, Drew. Much appreciated.
I've just checked and found that 'section' is now - as you would expect - a perch_blog_custom option. It would be worth adding this to the documentation as well!
Quick question on this... based on responsive above:
"Yes, once you've added a second post template, a select box appears on the edit form."
How does Perch recognise a "second post template"? As different from other templates in the templates/blog folder? I have tried adding post_xxx_xxx.html, but I don't get any options when adding a new post.
I am also going to use section in array to show only set posts based on section.
Thanks.
Sorry... just read the "README.txt" file... :-P
You need to add any alternate templates to the "post" folder inside the "templates/blog" folder.
"RTFM"!
ATT: Drew / Rachel - having a more intuitive way for clients to add a post to a section (with it's own template) rather than changing template after you add would be great.
FYI - if you keep the readme.txt file in the posts folder, even though no other template is in, it will ask the user to select what template they want, default or readme.txt? Delete the txt file and it goes away.