I have multiple sections (channels) that use the same index and _entry templates. In my index template, given that the section is dynamic, how do I define the current section and access it? Eg, I'd like to make the template's header dynamic: <h1>{{ section.name ~ " Blog" }}</h1>
.
Here is my fragile, hacked solution that I hope I never have to use in production:
I start things off by grabbing a section of the current URL. This returns a string, eg: "southwest-mn", that I use to load the actual section.
{% set handle = craft.request.getSegment(2) %}
Next, I convert the string to one that reflects the section's handle format, eg: blog_southwest_mn (I changed it from blogSouthwestMn to make this string wizardry faster and easier)
{% set sectionHandle = handle|replace('-', '_') %}
Now we can patch together a dynamic section name based on our URL, so let's grab the entries
{% set blog = craft.entries.section('blog_' ~ sectionHandle) %}
This is the most embarrassing part of the code... I'm not sure how to get to the actual section model, so I used the following to display the correct header in the template
{% if handle == "southwest-mn" %}
{% set blogTitle = "Southwest MN Blog" %}
{% endif %}
That's how I was able to at least get a prototype template working. But how can I load a dynamic section's model so I don't have to write such madness?
Thanks!