Forums / General / def, let and set

def, let and set

Author Message

Softriva .com

Sunday 20 August 2006 12:47:20 pm

Can someone explain to me the difference between def, let and set and which of them is/are deprecated?

Claudia Kosny

Sunday 20 August 2006 2:14:31 pm

Hi OOzy,

as far as I know 'let' and 'def' are responsible for declaring and defining new variables in a template, with 'let' being the deprecated form. The usage of 'def' differs a bit from 'let', e.g. 'let' had a scope and a name parameter, which 'def' does not have. Also you need to close an opened '{let...' with a '{\let}' whereas you can close '{def ...' with '{undef}', but you don't have to.
'set' changes the value of an existing variable, it can _not_ declare variables.

So the general usage is:
-Somewhere at the beginning of your template you declare all variables using
{def $variable1='foo'
$variable2='bar'}

Now you need to change the value of variable1:
{set $variable1='quux'}
Now variable1 has the value 'quux', variable2 still has 'bar'.

Please note that e.g. {set $variable3='newfoo'} will _not_ work, in fact you will get an error message that variable3 does not exist and can not be set.
At the same {def $variable1='newquux'} will not work as variable1 is already declared.

Now you decide that you do not need variable1 anymore (maybe to do some cleanup)
{undef $variable1}
Now variable1 does not exist anymore.

Now you decide that you want to get rid of all variables in your script, no matter where you declared them.
{undef}

Greetings from Luxembourg

Claudia