ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Templates - do they have to be redundant like that?

July 10, 2012 1:16am

Subscribe [1]
  • #1 / Jul 10, 2012 1:16am

    Heiko

    135 posts

    Hi there,

    I’m getting slowly back into the groove using EE, but I keep wondering if I really need to explicitly setup templates for each channel, although they are absolutely identical.

    Actually I only have two types of templates: a multi-entry-view and a single-entry-view, which currently I’m embedding based on the url path of each channel.

    So, I’m accessing the multi-entry-template for a channel like this:

    {preload_replace:channel="{segment_1}"}
    {site_header}
    {embed="site/index-view" channel="{channel}"}
    {site_footer}

    And the single-entry-template like this:

    {preload_replace:channel="{segment_1}"}
    {site_header}
    {embed="site/single-view" channel="{channel}"}
    {site_footer}

    It works beautifully, but it seems, that I have to duplicate those templates for each and every channel, just to get the path working. Am I missing the forest for the trees here or does it have to be like that?

    I’d love to just setup those two templates in my site-template-group and use them from there.

  • #2 / Jul 11, 2012 11:54am

    Kevin Smith

    4784 posts

    Hi Heiko,

    Of course, you don’t need to have a separate template for each channel. It looks like you’re on the right track here, but you do have one extra layer that’s not necessary. Why not just use {segment_3} to tell your templates which channel to display?

    In other words, something like this, where the URL for the “news” channel might look like http://example.com/site/template/news:

    {exp:channel:entries channel="{segment_3}" limit="10"}
        <h2>{title}</h2>
    <p>    {body}<br />
    {/exp:channel:entries}

  • #3 / Jul 13, 2012 1:02am

    Heiko

    135 posts

    Thank you very much! Finally I got it right… 😊

  • #4 / Jul 16, 2012 1:22am

    Heiko

    135 posts

    Well, sorry to bother you again, but it turns out, that my template structure is still not working, if I don’t create one template group with duplicated templates for each channel, that I’m using - which is really dull, because the templates are identical to the bit.

    How can I tell EE to make use of the single-entry-template, independently from the current URI?

    Ideally I only want to have one template group with two templates only, which then dynamically show entries from all the different channels.

    template_group
       index-view
       single-view
  • #5 / Jul 16, 2012 5:08am

    Heiko

    135 posts

    Alright, now I’ve reduced my overall template count to 1, using a combination of Stash and Switchee. :D

    {preload_replace:channel="{segment_1}"}
    
    {exp:stash:get name="interior" context="wrappers" scope="site" file="yes" save="yes" refresh="60" replace="no" output = "yes"}
    
    {exp:stash:set name='content'}
    {exp:switchee variable="{segment_2}" parse="inward"}
      {case value="''"}
        {site_ad_listing}
      {/case}
      {case default="yes"}
        {site_ad_single}
      {/case}
    {/exp:switchee}
    {/exp:stash:set}

    It works great, but I don’t know, if this is good pratice. So, if anyone has any experience to share, I’d be glad to hear about it.

  • #6 / Jul 16, 2012 10:24am

    Kevin Smith

    4784 posts

    Hmm… it looks good to me in general, though some parts are a bit confusing. Is this the whole master template? Are you actually using the channel variable that you’re setting with preload_replace anywhere?

    When it comes to best practices on using Stash, that’s going to be something better handled by our community since it’s a third-party add-on and I admittedly don’t have any experience with it.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases