0

I have an event block that displays images.

I want to have 3 options: - if event has image, display that image - if event url title has a certain keyword, display that image - else display a placeholder image

I don't know how to write the 2nd option to the existing code:

    {if event_photo}
        {exp:imgsizer:size src="{event_photo}" alt="{title}" width="300" height="450" class="displayBlock" quality="100"}
    {if:else}
        <img src="/images/_pages/_global/placeholder.jpg"/>
    {/if}
1

You need some RegEx for that.

Using the new conditionals operators of EECMS version 2.9:

{if event_photo}
    {exp:imgsizer:size src="{event_photo}" alt="{title}" width="300" height="450" class="displayBlock" quality="100"}
{if:elseif url_title *= "keyword"}
    {exp:imgsizer:size src="{other_photo}" alt="{title}" width="300" height="450" class="displayBlock" quality="100"}
{if:else}
    <img src="/images/_pages/_global/placeholder.jpg"/>
{/if}

Using switchee, if you can't update EECMS:

{exp:switchee variable="{event_photo}/{url_title}" parse="inward"}
    {!-- if the concatenation of both variables ends on "/", but has something before it --}
    {case value="#./$#"}
        {exp:imgsizer:size src="{event_photo}" alt="{title}" width="300" height="450" class="displayBlock" quality="100"}
    {/case}

    {!-- if there is "keyword" --}
    {case value="#keyword#"}
        {exp:imgsizer:size src="{other_photo}" alt="{title}" width="300" height="450" class="displayBlock" quality="100"}
    {/case}

    {case default="yes"}
        <img src="/images/_pages/_global/placeholder.jpg"/>
    {/case}
{/exp:switchee}
3
  • Oh okies, I will look into that tomorrow and see if I can get that to work. I don't think we are on EEv2.9 though. – user3076 Jul 16 '14 at 23:58
  • If you use switchee, you won't need EE2.9. Robson was smart to point out the two ways to handle it. Switchee is compatible with many versions back of EE, so if an upgrade to use native functionality isn't your cup of tea, Switchee will do it in a pinch. – Jean St-Amand Sep 15 '14 at 14:38
  • I just notice my solution just works if the keyword is on the beginning of url_title. I gonna fix it! Thanks for bring this to my attention, @JeanSt-Amand, even without intention. – Sobral Sep 15 '14 at 15:51

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.