5

I have a snippet that I use on nearly every page of a site. I need to give the admins some control in the fallback source of an image in that snippet. Now I know there is a parse order issue here as it works fine when dropped directly into the template, I am just wondering if there is a workaround?

    {exp:switchee variable="{segment_1}/{segment_2}" parse="inward"}    
    {case value="events/{segment_2}"}
        {exp:low_variables:parse var="lv_fallback_banner"}
            {exp:ce_img:pair src="{event_masthead}" height="270" min_width="1600" max_width="1600" fallback_src="{url}" crop="yes" allow_scale_larger="yes" filter="brightness,-80|grayscale|colorize,80,39,9,10"}style="background:url('{made}') no-repeat 50% 0; height: 270px;"
            {/exp:ce_img:pair}
        {/exp:low_variables:parse}
    {/case}     
    {case value="member-directory/{segment_2}"}
        {exp:low_variables:parse var="lv_fallback_banner"}
            {member_photo_gallery limit="1"}
                {exp:ce_img:pair src="{url}" height="270" min_width="1600" max_width="1600" fallback_src="{lv_fallback_banner}" crop="yes" allow_scale_larger="yes" filter="brightness,-80|grayscale|colorize,80,39,9,10"}style="background:url('{made}') no-repeat 50% 0; height: 270px;"
                {/exp:ce_img:pair}
            {/member_photo_gallery}
        {/exp:low_variables:parse}      
    {/case}     
    {case default="yes"}
        {exp:low_variables:parse var="lv_fallback_banner"}
            {exp:ce_img:pair src="{masthead}" height="270" min_width="1600" max_width="1600" fallback_src="{url}" crop="yes" allow_scale_larger="yes" filter="brightness,-80|grayscale|colorize,80,39,9,10"}style="background:url('{made}') no-repeat 50% 0; height: 270px;"
            {/exp:ce_img:pair}
        {/exp:low_variables:parse}
    {/case}                 
{/exp:switchee}
  • What is your low variable set for parsing? early or late? have you tried changing to exp:low_variables:pair instead of parse? – CreateSean Nov 23 '12 at 18:43
  • It is set to early parsing. I have also tried changing to pair. No luck yet. When I have a valid SRC variable the image parses as expected, but when the {masthead} field is empty the fallback is not working. I will update the origial post with my current snippet. – Dan Johnson Nov 24 '12 at 18:55
  • 1
    You're using the tag-syntax instead of the variable-syntax here. This means early/late parsing is irrelevant, as that only applies to the variable syntax: early parsing = before tags, late parsing = after tags. Also, switching between the :pair and :parse tags only makes a difference when having both single :parse tags and paired :parse tags in 1 template. That can cause conflicts, so it's recommended to use :single when using a single tag, and :pair when using a tag pair. – Low Nov 25 '12 at 11:20
  • Understood. The issue then is how can I get your Low Variables (with P&T Assets) to output a URL that CE-Image can parse? {lv_fallback_banner} outputs "{filedir_6}example.jpg" – Dan Johnson Nov 25 '12 at 20:40
  • 1
    What if you use {exp:ce_img:pair ... fallback_src="{exp:low_variables:single var='lv_fallback_banner'}" ... parse="inward"} as the CI Image opening tag. Make sure everything is on a single line. Having the :parse tag in a pair for a variable that needs extra processing (like Assets does with the {filedir_x} vars), only works for single tags at the moment. – Low Nov 26 '12 at 22:38
7

The lv_fallback_banner is an Assets variable type, which stores the data like this: {filedir_x}my-image.jpg. To parse the filedir-variable, you need to use the {exp:low_variables:single} tag, so Assets gets called and can process it (instead of just dumping the variable content in the template).

In this case, it will always return the parsed variable content, not the tagdata inside the :parse tag, so the ce_img tag will be lost. To solve, use the :single tag inside the ce_img tag's parameter:

{exp:ce_img:pair ... fallback_src="{exp:low_variables:single var='lv_fallback_banner'}" ... parse="inward"}

Also make sure everything is on a single line, or EE's template parser may choke.

6

Your first conditional statement is an advanced conditional (since it includes an AND clause), which means that both of your {preload_replace} variables are being called every time. Since subsequent {preload_replace} calls for the same variable are ignored, I'd guess that you're ending up with {event_masthead} every time, is that right?

  • 1
    If this is correct, then I would recommend using Croxtons IfElse plugin and parse inwards - that should fix it for you. – CreateSean Nov 23 '12 at 19:44
  • 1
    Can't really comment on Low Variables... so just adding to what's been said... Derek is spot on. As CreateSean said IfElse add-on could remedy that, e.g. wrap the whole conditional in {exp:ifelse parse="inward"}...{/exp:ifelse}. However, since this is a SN note IfElse can't be nested. If you use IfElse outside, you may want to use Switchee beta instead. (Switchee on Devot-ee here.) – notacouch Nov 23 '12 at 22:30
1

To follow-up on what Tyssen said: If you don't want to use a third-party plugin ( like switchee or ifelse ) you could do it with standard EE. However Tyssen's conditionals are still being considered advanced conditionals, so they won't solve your problem.

This should work though:

{if segment_1 == 'events'}
    {if segment_2 == ''}
        {preload_replace:group='event_'}
    {/if}
{/if}
{if segment_1 != 'events'}
    {if segment_2 != ''}
        {preload_replace:group=''}
    {if}
{/if}

More on conditionals: http://userguides.ellislab.com/expressionengine/templates/globals/conditionals.html

-1

To avoid using an advanced conditional and not necessarily having to use IfElse or Switchee (both of which are great by the way), you could do this instead:

{if segment_1 == 'events' AND segment_2 == ''}
    {preload_replace:group='event_'}
{/if}
{if segment_1 != 'events' AND segment_2 != ''}
    {preload_replace:group=''}
{/if}

That's no longer an advanced conditional because there's no if:else.

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.