Home » HTML » HTML_Template_Flexy » Bug #1974
IF conditions like x=="a"
Details
| Request #1974 | IF conditions like x=="a" |
|---|---|
| Submitted | 2004-07-24 19:33 UTC |
| From | aemadrid at gmail dot com |
| Status | Verified |
| Package | HTML_Template_Flexy |
| PHP Version | 4.3.7 |
| OS | Linux RH 2.1AS |
| Roadmaps | (Not assigned) |
Comments
[2004-07-24 19:33 UTC] aemadrid at gmail dot com
Description:
------------
Would you consider adding support for IF conditions like x=="a"? It could have a syntax like flexy:if="x:#a#"? It is kind of cumbersome to create switch case conditions with only simple true/false conditions like flexy:if="x" or flexy:if="!x" as it stands right now.
[2004-09-11 13:55 UTC] bat at flurf dot net
I figured out a way to do this. Suppose you want something like this (remembering that string literals are enclosed in #hashes#:
{if:user=#root#}<a href="...">Admin</a>{end:}
This syntax isn't supported. My solution is to add to your object a function like this:
function equal($x,$y) { return $x == $y; }
and then, instead of the above (illegal) syntax, use this:
{if:equal(user,#root#)}...<a href="...">Admin</a>{end:}
Works perfectly!
[2004-09-13 16:56 UTC] aemadrid at gmail dot com
Good thinking! Simple and effective. Thanks for the tip.
[2004-09-15 06:07 UTC] bat at flurf dot net
This trick is pretty powerful, actually. You want to have your template include other templates? Put something like this in the template html:
{includeTemplate(#froggy.html#)}
... and something like this in your object definition:
function includeTemplate($filename)
{
$content = new HTML_Template_Flexy(/* options... */);
$content->compile($filename);
return $content->bufferedOutputObject($this);
}
It works flawlessly!