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

$FNS->prep_conditionals() not Parsing?

Development and Programming

Mark Huot's avatar
Mark Huot
587 posts
17 years ago
Mark Huot's avatar Mark Huot

Ok, I know this is something silly, but I’m using $FNS->prep_conditionals() from within a MCP file. Just for testing I’m running the conditional on the following ‘template’:

$day = "{if entries}entries{/if}{if not_entries}not-entries{/if}";

This is the PHP running:

$variables = array('entries'=>'TRUE', 'not_entries'=>'FALSE');
$day = $FNS->prep_conditionals($day, $variables);

And here’s what I get:

{if TRUE}entries{/if} {if FALSE}not-entries{/if}

Is there a reason the variables are getting replaced correctly but not parsed? Does the prep_conditionals method have to be run from a template?

Thanks mark.

       
Daniel Walton's avatar
Daniel Walton
553 posts
17 years ago
Daniel Walton's avatar Daniel Walton

Yes Mark, The template parser plays the final role in either removing or retaining the sections of code between conditionals.

       
Paul Burdick's avatar
Paul Burdick
480 posts
17 years ago
Paul Burdick's avatar Paul Burdick

Yes, the prep_conditionals merely takes the array of data given to it and does matching in the EE conditionals to output a more PHP-parsable conditional that can then be converted later to real PHP and processed by eval(). You can see this happening around line 2839 of core.template.php in the current build of 1.6.

       
Mark Huot's avatar
Mark Huot
587 posts
17 years ago
Mark Huot's avatar Mark Huot

Huh, the reason I ask is because if I’m parsing a template in my MOD file it’d be nice to use the same syntax in the MCP file. Do you think I could get around this by creating a global $TMPL variable within my modules class before I run the conditionals?

       
Paul Burdick's avatar
Paul Burdick
480 posts
17 years ago
Paul Burdick's avatar Paul Burdick

Well, you would have to load the class first, as it is typically never called on the CP side, but yes, it looks like you should be able to simply call the advanced_conditionals() method.

       
Mark Huot's avatar
Mark Huot
587 posts
17 years ago
Mark Huot's avatar Mark Huot

Excellent! That’s much better news that what I was expecting. I’ll give it a shot and let you know what I come up with!

       

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.