We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Trouble with conditionals

Development and Programming

Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

This works:

{exp:image_properties src="<?php echo "$img_url" ?>" }
        height is {height} and width is {width}
        {if height > width }
            foo
            {exp:imgsizer:size src="<?php echo $img_url ?>" height="{img_size}" alt="{title}" id="placeholder"}
        {if:else}
            bar
            {exp:imgsizer:size src="<?php echo $img_url ?>" width="{img_size}" alt="{title}" id="placeholder"}
        {/if}
        {/exp:image_properties}

and this doesn’t:

{exp:image_properties src="<?php echo "$img_url" ?>" }

        {if height > width }
            foo
            {exp:imgsizer:size src="<?php echo $img_url ?>" height="{img_size}" alt="{title}" id="placeholder"}
        {if:else}
            bar
            {exp:imgsizer:size src="<?php echo $img_url ?>" width="{img_size}" alt="{title}" id="placeholder"}
        {/if}
        {/exp:image_properties}

Why would that be?

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
17 years ago
Sue Crocker's avatar Sue Crocker

Erin, I’m going to move this out of the general EE tech support queue. This question has to do with third party code.

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Does it?

While I did find this problem with a plugin (or two), I seems to be an EE parsing issue or something, does it not?

The way I see it, EE can’t do the {if} statement until it parses the {height} and {weight}. Does that sound right? Perhaps I am misunderstanding things, which is very possible.

Shall I see if I can duplicate this with EE plugins?

Thanks

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
17 years ago
Sue Crocker's avatar Sue Crocker
Shall I see if I can duplicate this with EE plugins?

That would make it more of a tech support issue at that point.

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Hokey dokey…I will see if I can throw together a template that duplicates it with EE-only plugins, etc as I suspect it is a parse issue or something.

Thanks

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell
Erin, I’m going to move this out of the general EE tech support queue. This question has to do with third party code.

Could I get some help on why this is happening? I have created a plugin that has only one tag (num_entries) and I would like to use it in a conditional. But it seems I can’t do it unless I first put the tag on the page ({num_entries}).

Is this a parse order problem or something?

I would like to do this:

{exp:categoree parse="inward"}
{if num_entries > 0 }
Do STUFF
{/if}

But it doesn’t work unless I do this:

{exp:categoree parse="inward"}
{num_entries}
{if num_entries > 0 }
Do STUFF
{/if}
       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Are you sending your variable and tagdata through the conditional prep routine in the Functions class? Conditional Variables (Template Class docs) Functions Class

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Nope, I didn’t know I had to as I hadn’t seen any examples of that in any code.

The example you linked to references boolean values. Mine is not, is that relevant?

So you are saying I need to create an array of my out values then pass it to the prep_conditionals function? Do I do that before or after my swap_var_single?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Regarding the correct order for conditionals and variable parsing (from my link above):

If you are scripting conditional variables in your module, then they should be done first when processing tag data before any other variables are parsed.

No, that they are boolean or not isn’t material. Check out mod.weblog.php, mod.comment.php, mod.simple_commerce.php etc. for real world usage examples.

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

You keep mention modules…this is a plugin…I assume you realize that and mean that that is not relevant?

I will check out those examples.

Thanks

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Yes, I realize that. Using the template class and operating on tagdata with one or the other are completely identical.

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

OK, I now have this in my plugin:

$result = $query->row;
        $num_entries = $query->row['total_files'];
        
        $tagdata = $FNS->prep_conditionals($TMPL->tagdata, $result);

        foreach ($TMPL->var_single as $key => $val)
        {
            switch ($val)
            {
                case "num_entries":
                    $tagdata = $TMPL->swap_var_single($val, $num_entries, $tagdata);
                    $this->return_data = $tagdata;
                    break;
            }
        }

And it still isn’t working when I do this:

{exp:categoree parse="inward"}
        {if num_entries > 0 }

            {exp:gallery:entries gallery="{gallery_name}" orderby="date" sort="desc" columns="10" rows="1"}
                {entries}
                {row_start} {/row_start}
                {row}
                <div class="thumbnail">
                    {if width > height}
                    <div class="landscape">
                        <a href="#" onclick="return getLandscapeImage('placeholder','{image_url}');">{exp:imgsizer:size src="{image_url}" width="{thumb_size}" alt="{title}" }</a>
                    </div>
                    {if:else}
                    <div class="portrait">
                        <a href="#" onclick="return getPortraitImage('placeholder','{image_url}');">{exp:imgsizer:size src="{image_url}" height="{thumb_size}" alt="{title}" }</a>
                    </div>
                    {/if}
                </div> <!-- thumbnail -->
                {/row}
                {row_blank} {/row_blank}
                {row_end} {/row_end}
            {/entries}
            
            {paginate}
                <div class="paginate">
                    {pagination_links}
                </div> <!-- paginate -->
            {/paginate}
            
            {/exp:gallery:entries}
        {/exp:categoree}
       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

You are only setting $this->return_data to the modified $tagdata if the plugin has a variable that it can parse. Since there’s no variable for it to parse, $this->return_data is never modified.

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell
You are only setting $this->return_data to the modified $tagdata if the plugin has a variable that it can parse. Since there’s no variable for it to parse, $this->return_data is never modified.

OK, you lost me. I thought I was getting it to parse ‘num_entries’ because it is inside the conditional? I must be not getting something simple here.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones
foreach ($TMPL->var_single as $key => $val)

It’s not a template variable unless you have the variable in the template. A variable has brackets, e.g. {foo}.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.