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.

a lot of snippets vs a buch of templates - what´s better

July 23, 2010 5:39am

Subscribe [2]
  • #1 / Jul 23, 2010 5:39am

    awa

    77 posts

    Hi,
    I need to serve 41 pages out of a template groups.
    I see to options:

    Having a template_group/index and serving all pages from that index template via conditionals and snippets. Something like

    {if segment_2 =="blah"}{snippet_blah} {if:else segment_2 =="fasel"} {snippet_fasel}....


    Having a template for each page, so
    template_group/index
    template_group/blah
    template_group/fasel


    Any performance issues? I read Lisas post re snippets vs embeds, but what about the conditionals in version 1?

    The only issue I´m unsure about is: What about snippets in snippets? Can I embed snippets into other snippets? That might be neccessary.

    At the moment I see both variants as equal, but I want to make sure, that I don´t overlook a point.

    Thanks
    awa

  • #2 / Jul 23, 2010 10:51am

    Boyink!

    5011 posts

    Ah - let’s back up a moment.

    In most cases if you are thinking that one rendered page == one EE template then something is amiss.

    Are all these pages the same structure and layout?  Is the content all stored in one channel?

    You should be able to one EE template that renders out many pages.  Most of my main template groups have 1-3 templates on average - regardless of how many pages they generate.

    With EE the whole notion of “Pages” really becomes unimportant - it’s more about how many different types of content you have.

    If, for example, your site was a restaurant directory, you’d likely have 2 main templates - one to serve up the index, and one to serve up the details.  The second template would do that for every restaurant entry you have.

    Now if index, blah and fasel are different page types (different layout) or different content types (blog, FAQ, timeline) then you’d have specific templates for them.

    It might be a good idea to take a look at http://www.train-ee.com/courseware/static/ - it’s the most basic tut I have but shows how one weblog/channel and one template can serve up an entire “static” section of a site.

  • #3 / Jul 23, 2010 2:52pm

    awa

    77 posts

    Ah - let’s back up a moment.
    Are all these pages the same structure and layout?  Is the content all stored in one channel?

    Basically they are 3 types of pages. The index, 5 order-pages and the rest are familiy-pages (it´s a site about animals, so order, familiy are meant in a taxonomical way.).

    I could use 3 templates, index, order and family and then hav everthing served from those 3, but I want to avoid the 3rd segment.

    I dont want

    TG/index
    TG/order/amphibians
    TG/order/snakes
    TG/familiy/toads
    TG/familiy/colubrids

    Instead I want

    TG/index
    TG/amphibians
    TG/snakes
    TG/toads
    TG/colubrids

    Makes for shorter URLs and also having the words order and familiy in the URL doesn´t bring any SEO advantages.

    This is why I came up with the snippets vs. templates thing 😉
    But sure, you´re abolutely right, having just a few well thought out templates that drive the whole site is a sign of good design.

    Cheers
    awa

  • #4 / Jul 23, 2010 4:26pm

    Boyink!

    5011 posts

    Hmm - part of me says having /family/ and /order/ in the URL may not be an SEO goal but is perfectly semantic as it describes the content I’m viewing and places it in the taxonomy. 

    Having to construct conditionals that are content specific doesn’t scale well - you’ll end up having to edit code just to publish a new entry. 

    However without having /order/ or /family/ in the url I can’t think of any better way to go about it - you’re essentially removing a hook that EE could use to pull the right templates in one way or another.

    The other note to make here is that conditionals that use {else:if} are advanced conditionals and are parsed late.  What this means is that all code in all clauses of the conditionals is evaluated first, then EE finds the “correct” one and renders it.  I’d suggest perusing the docs here:

    http://ellislab.com/expressionengine/user-guide/templates/globals/conditionals.html

    The takeaway there being to try and use simple conditionals as much as possible to keep EE’s performance as speedy as possible.

  • #5 / Jul 25, 2010 11:23am

    Boyink!

    5011 posts

    Funny where your brain goes when you get offline..😉

    A couple of ideas came to me here - one way to assign /family/ and /order/ layouts in one template w/o having those keywords in the URL would be to create a custom field in the channel.  I’d make it a drop-down with order and family as options.

    Then in your one single-entry template you’d do something along these lines

    {exp:channel:entries channel="animals" url_title="{segment_2}" limit="1" dynamic="no"} 
      {if my_type=="family"} 
        <family html>
        </family html>
      {/if}
    
      {if my_type=="order"}
       <order html>
       </order html>
      {/if}
    {exp:channel:entries}

    That assumes all animals are in one channel.

    The other thought is to put the two types into different channels (I’m not sure if the field structure for an order would be different from a family, if so this is what I would do).

    Then your template could be coded along these lines:

    {exp:channel:entries channel="order|family" url_title="{segment_2}" limit="1" dynamic="no"} 
      {if channel_short_name=="family"} 
        <family html>
        </family html>
      {/if}
    
      {if channel_short_namee=="order"}
       <order html>
       </order html>
      {/if}
    {exp:channel:entries}
  • #6 / Jul 26, 2010 5:36am

    awa

    77 posts

    Hi Michael,
    thanks for your great ideas.
    I think, I should have myself clearer. The order and the family pages are listing pages.

    The order page contains a list of families, that belong to that order and the
    familiy page contains a list of species, that belong to that familiy.

    The single entry pages are the species pages and they have a URL structure of
    tempate_group/entry/species_name
    So, absolutely the classical EE way to set it up. All SEs come out of the entry template.

    On the order pages the tag below pulls out all the related families.

    This is the amphibian order page and the categories 26|27|14|28|10 are frogs, salanders and the like. I hardcode that into the tag.
    The link goes to the respective familiy page.

    {exp:channel:entries channel="intro" category="26|27|14|28|10" orderby="title" sort="asc" dynamic="off"}
    <a href="http://{path=animals/{url_title}}">{title}</a> - {body}
    {/exp:channel:entries}

    I can´t build standard categories pages, since I´m not pulling content from the categoy I´m looking at, but one level down. E.g. looking at category amphibians means, that I want to list all subcats from that category.
    For those “blurbs” I have an extra intro channel, but this channels shares animal category tree with the animals, so for the purpose of this posting, it doesn´t matter.

    For the snake order page the code would look the same, just the category=”...” part would be different.

    So, the only possibility to avoid conditionals I see is to go with different templates.
    Regardless, if I have an order template and a familiy template or if I drive all out of the index page, I still need

    {if segment_x =="y"}
    {y}
    {/if}
    
    {if segment_x =="z"}
    {z}
    {/if}

    That would avoid the advanced contitionals (read about it, but forgot, thanks for the reminder).

    awa

  • #7 / Jul 26, 2010 8:01am

    Boyink!

    5011 posts

    So you don’t want /family/ or /order/ but are ok with /entry/?  :gulp:

    Hardcoded categories…and bunch of content-specific templates…just not thing I generally like.

    Did you experiment with relationships rather than categories? 

    Or I almost wonder - because of the number of levels in your hierarchy - if Structure would be a good alternative.

  • #8 / Jul 27, 2010 4:07am

    awa

    77 posts

    Hi Michael,
    I tried structure, but it´s not really what I need (or maybe I just couldn´t figure it out 😊)
    Relationships aren´t an option, because there are too many of them and adding a new entry would mean to revise a lot of existing relationshops in more than a few cases.
    It may take a while , but when I´m done, I´ll post what I did so others can see and comment.

    Cheers
    awa

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

ExpressionEngine News!

#eecms, #events, #releases