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
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?
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”.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.