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.

if, if:else, and all else fails!

September 04, 2010 4:42pm

Subscribe [3]
  • #1 / Sep 04, 2010 4:42pm

    James Hurst

    48 posts

    Hmm - so i’ve been trying out various combinations of the conditionals - and keep drawing a blank (literally!) anyone got any ideas about why:

    {exp:weblog:entries weblog="home" }
    {reverse_related_entries}
    {if count >= "1"}
            <div class="span-24 last">
                    <hr >
            <div id="slider">
                                {/if}
                                    <a href="http://{path={url}{weblog}/{url_title}}">_                                    {image}_                                        {if homepage_image !=''}_                                            {exp:imgsizer:size src="{homepage_image}" width="950px" height="400px" base_path="/home/printclub/NV6S9T0F/htdocs/" base_cache="/home/printclub/NV6S9T0F/htdocs/alpha/images/sized"}_                                            {sized}</a>
                                            {if:else}
                                                {exp:imgsizer:size src="{image_file}" width="950px" height="400px" base_path="/home/printclub/NV6S9T0F/htdocs/" base_cache="/home/printclub/NV6S9T0F/htdocs/alpha/images/sized"}
                                                {sized}</a>
                                            {/if}
                                        {/exp:imgsizer:size}
                                        {/image}
                                    <div id="htmlcaption_{entry_id}" class="nivo-html-caption">
                                    <em>{weblog}: </em><a href="http://{path={url}{weblog}/{url_title}}">{title}</a>
                                    
    
                                    </div>
                                {if count==total_results}
            </div>
            </div>
    {/if}
    {/reverse_related_entries}
    {/exp:weblog:entries}

    Would result in the ‘white-screen of a conditional error’?

    If its useful - i’m using Pixel and Tonic’s Playa and Matrix - and both the

    {image_file}
    and
    {homepage_image}

    work beautifully when stripped out of the if, if:else conditional… and taking the ‘if count == total_results out of the equation makes no difference.

    In an ideal world (and which doesn’t seem to work) I would love to

    {image}
    {exp:imgsizer:size src="{if homepage_image !=''}{homepage_image}{if:else}{image_file}{/if}" width="950px" height="400px" base_path="/home/printclub/NV6S9T0F/htdocs/" base_cache="/home/printclub/NV6S9T0F/htdocs/alpha/images/sized"}
    {sized}</a>
    {/exp:imgsizer:size}
    {/image}


    I’m trying to set up a system where the user is able to relate an item to a homepage slideshow - but allows for a specific homepage slideshow image to be used in case the imd Sizr crop isn’t acceptable.

    Any help much appreciated.

    James

  • #2 / Sep 05, 2010 4:28pm

    Greg Salt

    3988 posts

    Hi James,

    I would recommend stripping this down to its bare minimum until you are confident that a basic skeleton works then adding in your real data a piece at a time until something breaks. However, this code looks like it might be the problem:

    {image}
        {if homepage_image !=''}
            {exp:imgsizer:size src="{homepage_image}" width="950px" height="400px" base_path="/home/printclub/NV6S9T0F/htdocs/" base_cache="/home/printclub/NV6S9T0F/htdocs/alpha/images/sized"}
                {sized}</a>
        {if:else}
            {exp:imgsizer:size src="{image_file}" width="950px" height="400px" base_path="/home/printclub/NV6S9T0F/htdocs/" base_cache="/home/printclub/NV6S9T0F/htdocs/alpha/images/sized"}
                {sized}</a>
        {/if}
            {/exp:imgsizer:size}
    {/image}

    What you are doing here is trying to display only the opening tag of imgsizer with differing parameters based upon the value of a field. This is bad practice generally and you should enclose the entire plugin including the end tag inside a conditional block. This particular example though will always fail because you are using Advanced Conditionals. Advanced Conditionals are evaluated after all the EE tags are parsed so this code is declaring two opening tags for imgsizer. Try it like this:

    {image}
        {if homepage_image !=''}
            {exp:imgsizer:size src="{homepage_image}" width="950px" height="400px" base_path="/home/printclub/NV6S9T0F/htdocs/" base_cache="/home/printclub/NV6S9T0F/htdocs/alpha/images/sized"}
                {sized}</a>
            {/exp:imgsizer:size}
        {/if}
        {if homepage_image == ''}
            {exp:imgsizer:size src="{image_file}" width="950px" height="400px" base_path="/home/printclub/NV6S9T0F/htdocs/" base_cache="/home/printclub/NV6S9T0F/htdocs/alpha/images/sized"}
                {sized}</a>
            {/exp:imgsizer:size}
        {/if}    
    {/image}

    Whether there might be other issues caused by the 3rd party fields I can’t say. If you continue to have problems with this then please try simplifying the blocks and putting placeholder code in until you can identify where the issue is.

    Cheers

    Greg

  • #3 / Sep 06, 2010 7:59pm

    James Hurst

    48 posts

    Hi Greg - that perfect.

    Thank you for the response - and the link through to the parse order of advanced conditionals.

    All the best
    James

  • #4 / Sep 07, 2010 11:16am

    Sue Crocker

    26054 posts

    Glad Greg was able to help. Don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases