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.

Too many {if} Statements

October 03, 2013 11:17am

Subscribe [3]
  • #1 / Oct 03, 2013 11:17am

    Businessport46

    9 posts

    I have a large selection of {if} statements in the header template of my website and those statements check the page name and deliver meta data that is relevant, the problem I have is I have too many statements and as such they stop rendering after a certain number and no data is display at all.  Here is an example of my code:

    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" c>
      <title>{embed:my_page_title} | {site_name}</title>
      <meta name="keywords" c embed:my_page_title=="Home"}{exp:channel:entries channel="meta_data" entry_id="101"}{meta_tag}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="About us"}{exp:channel:entries channel="meta_data" entry_id="102"}{meta_tag}{/exp:channel:entries}{/if} 
    {if embed:my_page_title=="Training"}{exp:channel:entries channel="meta_data" entry_id="105"}{meta_tag}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Sectors"}{exp:channel:entries channel="meta_data" entry_id="106"}{meta_tag}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Energy"}{exp:channel:entries channel="meta_data" entry_id="107"}{meta_tag}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Infrastructure"}{exp:channel:entries channel="meta_data" entry_id="108"}{meta_tag}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Defence"}{exp:channel:entries channel="meta_data" entry_id="109"}{meta_tag}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Our Clients"}{exp:channel:entries channel="meta_data" entry_id="110"}{meta_tag}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Contact"}{exp:channel:entries channel="meta_data" entry_id="111"}{meta_tag}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="News"}{exp:channel:entries channel="meta_data" entry_id="112"}{meta_tag}{/exp:channel:entries}{/if}">
     
    <meta name="description" c embed:my_page_title=="Home"}{exp:channel:entries channel="meta_data" entry_id="101"}{meta_description}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="About us"}{exp:channel:entries channel="meta_data" entry_id="102"}{meta_description}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Training"}{exp:channel:entries channel="meta_data" entry_id="105"}{meta_description}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Sectors"}{exp:channel:entries channel="meta_data" entry_id="106"}{meta_description}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Energy"}{exp:channel:entries channel="meta_data" entry_id="107"}{meta_description}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Infrastructure"}{exp:channel:entries channel="meta_data" entry_id="108"}{meta_description}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Defence"}{exp:channel:entries channel="meta_data" entry_id="109"}{meta_description}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Our Clients"}{exp:channel:entries channel="meta_data" entry_id="110"}{meta_description}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="Contact"}{exp:channel:entries channel="meta_data" entry_id="111"}{meta_description}{/exp:channel:entries}{/if}
    {if embed:my_page_title=="News"}{exp:channel:entries channel="meta_data" entry_id="112"}{meta_description}{/exp:channel:entries}{/if}">

    Even writing all this code out didn’t feel like the ideal solution but after reading an article on “chunking” it seemed like this was a suggested solution. This isn’t practical and I was wondering if there is an different way to do this that stops the code limit and is more optimised and realistic.

    Thanks in advance.

  • #2 / Oct 04, 2013 4:41am

    Businessport46

    9 posts

    Anyone, this it causing me big issues and holding up my project :-(

  • #3 / Oct 04, 2013 5:14am

    deswork

    122 posts

    Not sure about your problem, but have you looked at http://devot-ee.com/add-ons/seolite as an alternative?

    Wayne.

  • #4 / Oct 04, 2013 9:41am

    Businessport46

    9 posts

    Not sure about your problem, but have you looked at http://devot-ee.com/add-ons/seolite as an alternative?

    Wayne.

    Thanks for the reply but I’d rather find a way to do this without a plugin, surely it can’t need a plugin to do something so simple?

  • #5 / Oct 04, 2013 11:50am

    Chriiiiso

    46 posts

    You are way over-complicating things.  Let EE do the work.  Just make a channel field for the meta data.  Then you can just fill out each entry as needed and use one tag without conditionals.

  • #6 / Oct 04, 2013 11:51am

    Chriiiiso

    46 posts

    And I second SEO Lite, it works great and is free.  Unless you’re opposed to saving time for some reason.

  • #7 / Oct 10, 2013 5:31am

    Dadonbike

    2 posts

    Here’s a different page/embed approach to ponder, it will make things much easier.

    Think inside out and consider using partials.

    Heres our layout. Template = layout/.default

    <!DOCTYPE html>
        <html lang="en">
         <head>
          <title>{exp:stash:head_title} - LocalYak</title>
          {sn_head}
          {gv_jquery}
          {exp:stash:head_links}
          {gv_google_analytics}
         </head>
         <body>
          {sn_body_top}
          <div id="main_bkgd">
           <div id="main" class="device_{ress} view_{view}">
            {exp:stash:content_above}
            <div id="content" class="{if ress > 1}rounded{/if} {exp:stash:get name='content_class'}">
             {exp:stash:content}
            </div>
            {exp:stash:content_below}
           </div>
          </div>
          {sn_footer}
         </body>
        </html>

    And heres a (page) template that calls and uses that layout.

    {embed="layout/.default"}
        {exp:stash:set name='head_title'}Compare{/exp:stash:set}
        {exp:stash:set name='head_links'}
         <link rel='stylesheet' type='text/css' media='screen' href="{stylesheet='advertise/.css_advertise'}" />
         <link rel='stylesheet' type='text/css' media='screen' href="{stylesheet='pages/.css_pages'}" />
         <meta name="description" c | Compare LocalYak advertising packages" />
        {/exp:stash:set}
        {exp:stash:set name='content_class'}tab-advertise outline{/exp:stash:set}
        {exp:stash:set name='content'}
         <div class="page_select body_wrap">
          <h1>Compare packages</h1>
          [put your page content here…. or if you are forced to like we did on this occassion, create an extra embed]{embed="advertise/.select_type"}
         </div>
        {/exp:stash:set}

    And if you need to show different content for the page, simply wrap using simple conditional like this

    {if segment_3 == ""}
         {exp:stash:set name='content_class'}category splash{/exp:stash:set}
         {exp:stash:set name='content'}some content or tags{/exp:stash:set}
        {/if}
        {if segment_3 != ""}
         {exp:stash:set name='content_class'}category splash{/exp:stash:set}
         {exp:stash:set name='content'}some different content or tags{/exp:stash:set}
        {/if}

    Our site is mostly built on that one single default layout, however we do use a total of seven layouts. About partials

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

ExpressionEngine News!

#eecms, #events, #releases