PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_Template_Flexy » Bug #1974

IF conditions like x=="a"

Details

Request #1974IF conditions like x=="a"
Submitted2004-07-24 19:33 UTC
Fromaemadrid at gmail dot com
StatusVerified
PackageHTML_Template_Flexy
PHP Version4.3.7
OSLinux 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!