Forums / Install & configuration / { let.. and { default... - What's the diffrence?

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

Author Message

Alexei Pechekhonov

Wednesday 08 January 2003 6:40:07 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)?
Alexei

Jan Borsodi

Thursday 09 January 2003 1: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'}

--
Amos

Documentation: http://ez.no/ez_publish/documentation
FAQ: http://ez.no/ez_publish/documentation/faq

sergey podlesnyi

Monday 27 January 2003 9:04:38 am

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}

sergey podlesnyi

Monday 27 January 2003 9:39:25 am

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}

Jan Borsodi

Monday 27 January 2003 12: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".

--
Amos

Documentation: http://ez.no/ez_publish/documentation
FAQ: http://ez.no/ez_publish/documentation/faq

sergey podlesnyi

Tuesday 28 January 2003 12: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.