Movatterモバイル変換


[0]ホーム

URL:


LightnCandy option: FLAG_ELSE

Resolve{{else}} or{{^}} as handlebars specification. Otherwise,{{else}} will be resolved as normal variable, and {{^}} will cause template error.

Sample Codes

The default behavior:{{else}} will look for the value of 'else' key.

Data:
array("else"=>"OK")
Template:
{{else}}
Result:
OK
Source Code
require('./vendor/autoload.php');useLightnCandy\LightnCandy;$template="{{else}}";$php=LightnCandy::compile($template);$render=LightnCandy::prepare($php);$data=array("else"=>"OK");echo$render($data);
Data:
array("foo"=>true)
Template:
{{#iffoo}}FOO{{else}}BAR{{/if}}
Result:
FOOBAR
Source Code
require('./vendor/autoload.php');useLightnCandy\LightnCandy;$template="{{#if foo}}FOO{{else}}BAR{{/if}}";$php=LightnCandy::compile($template);$render=LightnCandy::prepare($php);$data=array("foo"=>true);echo$render($data);

{else}}will do the else logic whenFLAG_ELSE enabled.

Used option: FLAG_ELSE

Data:
array("foo"=>true)
Template:
{{#iffoo}}FOO{{else}}BAR{{/if}}
Result:
FOO
Source Code
require('./vendor/autoload.php');useLightnCandy\LightnCandy;$template="{{#if foo}}FOO{{else}}BAR{{/if}}";$php=LightnCandy::compile($template,array("flags"=>LightnCandy::FLAG_ELSE));$render=LightnCandy::prepare($php);$data=array("foo"=>true);echo$render($data);

Search the cookbook

Generated at 2022-03-21T13:13:56.019Z

[8]ページ先頭

©2009-2025 Movatter.jp