Plugin

Archived
Forum
(read-only)

IfElse

ExpressionEngine 1.x, ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

Evaluating Greater/Less than with IfElse + Stash

Support Request

Brainwrek
Brainwrek

I’m surely missing something simple… but I’ve tried several iterations of this with poor results.  Perhaps you can help to spot my mistake(s)?

{exp:stash:set parse_tags="yes"}
{exp
:channel:entries}
{stash
:stashed_comment_total}{comment_total}{/stash:stashed_comment_total}
{
/exp:channel:entries}
{
/exp:stash:set}

{exp
:ifelse parse="inward"}
{if 
"stashed_comment_total" <= "99"}<a href="blah/reply" title="Reply" class="reply_button">Reply</a>{/if}
{if 
"stashed_comment_total" >= "100"}<span class="reply_button_closed">Closed</span>{/if}
{
/exp:ifelse} 

The problem is that regardless of how many comments I have, the code always defaults to the >= 100 option.  I can confirm that stash is setting the correct number (which is less than 100), but I still can’t ever get it to show the Reply button.

Ideas?

Thanks.

Mark Croxton
# 1
Developer
Mark Croxton

You won’t have any luck trying to use stash variables like that. Also there’s no benefit in using IfElse in this context: Try this:

{if "{exp:stash:get name='stashed_comment_total'}" <= "99"}<a href="blah/reply" title="Reply" class="reply_button">Reply</a>{/if}
{if 
"{exp:stash:get name='stashed_comment_total'}" >= "100"}<span class="reply_button_closed">Closed</span>{/if} 

 

Mark Croxton
# 2
Developer
Mark Croxton

You could also do this:

{exp:stash:set parse_tags="yes" type="snippet"}
{exp
:channel:entries}
{stash
:stashed_comment_total}{comment_total}{/stash:stashed_comment_total}
{
/exp:channel:entries}
{
/exp:stash:set}

{if stashed_comment_total 
<= 99}<a href="blah/reply" title="Reply" class="reply_button">Reply</a>{/if}
{if stashed_comment_total 
>= 100}<span class="reply_button_closed">Closed</span>{/if} 
Brainwrek
# 3
Brainwrek

Yep, that’s the first thing I tried, but it breaks badly.  I get these PHP errors when using the suggested code:

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<
h4>A PHP Error was encountered</h4>

<
p>SeverityUser Warning</p>
<
p>Message:  Invalid EE Conditional Variable{if "{exp:stash:get name='stashed_comment_total'}</p>
<p>Filename: libraries/Functions.php</p>
<p>Line Number: 2843</p>

</div><div style="
border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<
p>SeverityUser Warning</p>
<
p>Message:  Invalid EE Conditional Variable{if "{exp:stash:get name='stashed_comment_total'}</p>
<p>Filename: libraries/Functions.php</p>
<p>Line Number: 2843</p>

</div><div style="
border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<
p>SeverityWarning</p>
<
p>Message:  Cannot modify header information headers already sent by (output started at /path/to/my_EE_system_folder/codeigniter/system/core/Exceptions.php:170)</p>
<
p>Filenamecore/Common.php</p>
<
p>Line Number412</p>

</
div

This result surprised me greatly, because Switchee and IfElse are normally so straight-forward.  After several attempts, I was able to get rid of the PHP errors using my code above—at the expense of losing the evaluation functionality.  Weird.

Brainwrek
# 4
Brainwrek

STOP the presses… I just figured it out.  Sometimes fresh eyes help.  The parse=“inward” parameter was throwing it off.  I removed it from my original code.  Inserted your suggested code and it works perfectly now.

Thank you, Mark.

Mark Croxton
# 5
Developer
Mark Croxton

There is a bug in EE conditionals since EE 2.5.1 you should be aware of:
http://expressionengine.com/forums/viewthread/223416/

Also, IfElse can’t parse those ‘{exp:’ tags so it would throw an error anyway. The only reason it doesn’t with parse=“inward” removed is because it is parsed later than the inner {exp: tags . Like I said before, there’s no need to use IfElse at all with your code.

Brainwrek
# 6
Brainwrek

You’re right!  Awesome.  Thanks again.