1

I have some simple conditionals mixed with some advanced conditionals. I've just downloaded Switchee and IfElse and am trying to figure out which plugin is best for each situation. Can someone help shed some light for me by giving me a bit of advice to clarify the best case to use each?

Here is my complete template's code: http://pastie.org/private/fifymxyldxu01jbex6zbq

I'm having some trouble understanding parsing orders, so any wisdom would be greatly appreciated!

  • You don't need an addon to do what you're showing in your code and there should be no parse order issues. Please post your full code and tell us what isn't working. – Anna_MediaGirl Nov 5 '13 at 18:45
  • hi @Anna_MediaGirl - I just added the channel:entries tag to make it more clear. The res of the code is just more html/ee variables/ee conditionals that are all similar to the rest of the code that I've posted. It's all working, but my pages are loading incredibly slow. – jennetcetera Nov 5 '13 at 18:49
  • I am confident your page isn't loading slow because of this code. This is very basic EE code with straightforward conditionals. Are all your page loads slow or just the page loads that use this template? – Anna_MediaGirl Nov 5 '13 at 18:53
  • This particular page runs slightly slower, but it's getting better since I've been cleaning up the code. Now, the page is approx. 880 lines of code with about 100 {if}'s. But you don't think it's the conditionals? I thought that conditionals like this is what the IfElse plugin was for (devot-ee.com/add-ons/ifelse) but maybe I'm misunderstanding? – jennetcetera Nov 5 '13 at 18:58
  • Ah, I see... you aren't posting all your code. Please post all your code here or using pastie.org – Anna_MediaGirl Nov 5 '13 at 19:01
3

You are doing a ton in your template. After a quick look I'd say your slowness is related to your relationship fields.

I suggest installing the EE Debug Tool to determine what specifically is "slow" on the page load. That will help you decide how to optimize the template.

I also suggest taking a look at CE Cache to see if it makes sense for your project.

1

If all this are fields within the same exp:channel:entries, to use switchee or IfElse will make no difference.

Conditionals which uses module data are parsed by the module. There's no reason for use an addon.

Take a look at this answer of Low.

Or start by the slide 66 of his presentation.

The key to use this add-ons is to avoid unnecessary parsing, what, in your case, can be done just by not using native Playa tags.

Try to make them to be parsed after the exp:channel:entries conditionals.

For example, take note of how much memory and how many queries your templates uses now. Then start to replace the Playa fields that are inside conditionals by module tags.

{if pre_event_banner_extra_info != ''}
    <img class="placeholder" src="{pre_event_banner_extra_info}" width="336" height="305" alt="image description" />
{if:else}
{pre_event_video show_future_entries="yes" show_expired="yes" status="open|not blog|homepage feature"}
    <a href="http://{video_player_url}?autoplay=1" class="vimeo" rel="gallery" title="{title}"><img class="placeholder" src="{featured_image_sm}" width="336" height="305" alt="image description" /></a>
{/pre_event_video}
{/if}

By:

{exp:switchee variable = "{pre_event_banner_extra_info}" parse="inward"}

    {case value=""}
        {exp:playa:children entry_id="{emebd:e-entry_id}" field="pre_event_video" show_expired="yes" status="open|not blog|homepage feature"}
            <a href="http://{video_player_url}?autoplay=1" class="vimeo" rel="gallery" title="{title}"><img class="placeholder" src="{featured_image_sm}" width="336" height="305" alt="image description" /></a>
        {/exp:playa:children}
    {/case}

    {case default="Yes"}
        <img class="placeholder" src="{pre_event_banner_extra_info}" width="336" height="305" alt="image description" />
    {/case}

{/exp:switchee}

Check your memory and queries again.

Now, playa is another module and its tags will be discarded before parsing by switchee when not necessary.

  • Hi @Robson - I see you found my full code on pastie above. Thanks for the info from Low. I understand what those documents are saying, so maybe I'm misunderstanding what exactly Switchee and IfElse would be used for. Are you familiar with those plugins? – jennetcetera Nov 5 '13 at 19:28
  • Switchee is part of my default EECMS installation. I used it on all my projects. I gonna update my answer to help you a little more. – Robson Sobral Nov 5 '13 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.