This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Install & configuration » { let.. and { default... - What's the...
expandshrink

{ let.. and { default... - What's the diffrence?

{ let.. and { default... - What's the diffrence?

Wednesday 08 January 2003 3:40:07 pm - 5 replies

Does somebody know (or can explaine me ) the difference of two statements in template files for variables settings?
You may recognize { default ... } <class_tpl_content>{/default} in every class tpl. Please, what does it make difference {let statement (for section tpls) and {default statement (for both, section and class tpls)?
Alexei

Thursday 09 January 2003 10:56:24 am

> Does somebody know (or can explaine me ) the difference of
> two statements in template files for variables settings?
> You may recognize { default ... }
> <class_tpl_content>{/default} in every class tpl. Please,
> what does it make difference {let statement (for section
> tpls) and {default statement (for both, section and class
> tpls)?

let and default are almost the same thing in that they only set a variable if it does not already exist. However let will issue an error if the variable exists and default will not.

default is often used in included templates where you might have default values which are most used but which may be overridden by the including template.

Example:

mytemplate.tpl:
{default size=5}
size={$size}
{/default}

main.tpl:
{include uri='mytemplate.tpl'}
{include size=10 uri='mytemplate.tpl'}

Monday 27 January 2003 6:04:38 pm

Is it possible to modify values of variables? E.g.

{let i=1}
{section loop=10}
{let i=sum($i,1)}
{/section}

or just

{let x=10}
{let x=$x + 20}

Monday 27 January 2003 6:39:25 pm

Is it possible to modify values of variables? E.g.

{let i=1}
{section loop=10}
{let i=sum($i,1)}
{/section}

or just

{let x=10}
{let x=$x + 20}

Monday 27 January 2003 9:23:43 pm

> Is it possible to modify values of variables? E.g.
>
> {let i=1}
> {section loop=10}
> {let i=sum($i,1)}
> {/section}

Yes, however you need to use set to modify existing variables.
{let i=1}
{section loop=10}
{set i=sum($i,1)}
{/section}
{/let}

You also need an ending let which will unset the variable (same with default).

> or just
>
> {let x=10}
> {let x=$x + 20}

The template engine does not have specialized arithmetic operators built in like other engines, instead it relies on custom template to do the work.
The template behaves much like LISP (Used in Emacs for instance), ie. the operator is written before the operands.

x=1+2+3+4+5+6
{set x=sum(1,2,3,4,5,6)}

y=a*x+b
{set y=sum(mul($a,$x),$b)}

{set a=sum(and($b,$c,$d),or($e,$f,$g))}
The and will return $d if all input are "true" and the or will return the first that is "true".

Tuesday 28 January 2003 9:11:36 am

Thanks a lot Jan! Your reply is absolutely comprehensive.

Sometimes I reply to newbies' questions here but this is your deep knowledge of EZ Publish that helps a lot to fill the gap until complete documentation is available.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from