3

I've frequently done this with success:

{if '{exp:my_plugin:my_method}'}My method returned true{/if}

Or the opposite also works:

{if '{exp:my_plugin:my_method}' == '0'}My method returned false{/if}

However, doing this for methods with dynamic parameters that also return a string instead of a boolean seems to be impossible - eg (inside of a channel entries tag):

{if '{exp:my_plugin:my_method entry_id="{entry_id}"}' == 'blah'}My method returned the word blah{/if}

Interestingly, calling the plugin outside the conditional at least once in the same template makes the conditional work as expected:

test output: {exp:my_plugin:my_method entry_id="{entry_id}"}
{if '{exp:my_plugin:my_method entry_id="{entry_id}"}' == 'blah'}My method returned the word blah{/if}

... but this is obviously far too weird and fragile to be useful!

Wondering if I'm missing something obvious or making a mistake?

2 Answers 2

1

Try by using parse="inward" parameter within the plugin tag like:

{if '{exp:my_plugin:my_method entry_id="{entry_id}" parse="inward"}' == 'blah'}My method returned the word blah{/if}
2
  • 2
    It would be great if you could add an example to your answer to demonstrate what you mean, and what the parameter does (this would especially help new users who have not used that parameter before). Feb 10, 2013 at 9:10
  • This didn't work for me unfortunately, though it could be due to already using parse="inward" on an outer Switchee tag. Sep 26, 2013 at 11:54
1

Digital Surgeons appear to have made a plugin which works around this particular problem:

http://devot-ee.com/add-ons/ifify

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.