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

if tags not parsed by parse_variables

Development and Programming

MetalArend's avatar
MetalArend
9 posts
13 years ago
MetalArend's avatar MetalArend

I’m doing the following inside a module…

I have a plugin tag {exp:blau:save}{/exp:blau:save}, to try to gather form data, and do a special action based on the information gathered from that form data.

Inside those tags, there is some content, where I parse the information that should be written to my database, like: {exp:blau:save}this is some content that I want to get inside my module function{/exp:blau:save}

When the page gets called and the plugin gets parsed, I first save the partially parsed (global variables and such) content from inside my tags, and save them as a string. After that, I gather the form input from the $this->EE->input->post array, and use the function parse_variables to parse the variables gathered from the form input inside my content string. The result is that all my tags inside my content string are replaced with their value, as it should be, but any {if} tags using those variables are left alone.

An example: {exp:blau:save} {global_variable_text}{if form:name}{form:name}{/if} {if form:name2}{form:name2}{/if} {/exp:blau:save}

The content inside the module tags that is put inside the string is: Text from the global variable{if form:name}{form:name}{/if} {if form:name2}{form:name2}{/if}

After calling the function parse_variables I get: Text from the global variable{if Bart}Bart{/if} {if Reunes}Reunes{/if}

As where I expect: Text from the global variableBart Reunes

Anybody any idea as to what could be going wrong? I tried to replace {if form:name} with {if "{form:name}”}, but still those if tags keep popping up inside the string. Is there a function I need to call after parse_variables to clean stuff like this up? Or am I just doing it completely wrong?


Bart Reunes, PHP Developer @ Blau

       
Enviromed's avatar
Enviromed
375 posts
13 years ago
Enviromed's avatar Enviromed

These links may help. Good luck!

http://devot-ee.com/add-ons/ifelse http://loweblog.com/downloads/ee-parse-order.pdf

       
MetalArend's avatar
MetalArend
9 posts
13 years ago
MetalArend's avatar MetalArend

Thanks for the fast reply.

The ifelse addon is not really what I am looking for, as the if statement can never be parsed before I provide the parse_variables function with the values for those variables. And the ee-parse-order page from low is always the first thing I check, but…

Assuming that I parse my variables with the parse_variables function, the if-statements will also be parsed at that exact same moment - no? It seems as if the parse_variables function only parses the variables, without even looking at any “simple if” tags where those variables are being used.

So is there anything else I might be forgetting?

       
NicoDG's avatar
NicoDG
26 posts
13 years ago
NicoDG's avatar NicoDG

Hi,

You could use the following add-on which lets you access POST and GET variables inside your templates http://devot-ee.com/add-ons/get-post-parameters That way you don’t have to set up your own parsing methods.

Cheers, Nico

       
MetalArend's avatar
MetalArend
9 posts
13 years ago
MetalArend's avatar MetalArend

Thanks, NicoDG. But what to do with the following: I parse some special tags, that have different values, depending on a combination of values from some post values.

And does this basically mean that using parse_variables is expected to not parse those {if} tags?

       
NicoDG's avatar
NicoDG
26 posts
13 years ago
NicoDG's avatar NicoDG

No, you have to call parse_conditionals to parse the conditionals. But it is possible to check those conditionals in your template based on your post variables

{if "{your_post_var}” == “value1”} Do this {/if}

       
MetalArend's avatar
MetalArend
9 posts
13 years ago
MetalArend's avatar MetalArend

Found the solution: call $this->EE->TMPL->simple_conditionals, with as the first parameter the string, and the second the variables (pay attention to the different ways to add the variables in parse_variables and simple_conditionals)… Thanks to NicoDG for pointing me in the right direction.

For everybody out there searching for solutions like this: as you won’t find these functions in the user guide, the best thing to do is just go into the php class files, and simply go through the code 😉 In this case, the file you would want to read is “/admin/expressionengine/libraries/Template.php”.

       

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.