EllisLab text mark
Advanced Search
     
$FNS->prep_conditionals() not Parsing?
Posted: 18 September 2007 10:06 AM   [ Ignore ]
Avatar
Joined: 2006-01-05
632 posts

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.

 Signature 
 
Posted: 18 September 2007 10:44 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-22
575 posts

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

 Signature 

(a.k.a the_butcher)

 
Posted: 18 September 2007 11:35 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2002-08-05
490 posts

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.

 
Posted: 18 September 2007 12:01 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2006-01-05
632 posts

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?

 Signature 
 
Posted: 18 September 2007 12:07 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2002-08-05
490 posts

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.

 
Posted: 18 September 2007 12:08 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2006-01-05
632 posts

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!

 Signature