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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 20 2025 06:39:04
Script start
Timing: Jan 20 2025 06:39:04
Module start 'layout'
Timing: Jan 20 2025 06:39:04
Module start 'content'
Timing: Jan 20 2025 06:39:04
Module end 'content'
Timing: Jan 20 2025 06:39:04
Script end

Main resources:

Total runtime0.0188 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0067 589.0234152.6094
Module start 'layout' 0.00670.0048 741.632839.3984
Module start 'content' 0.01150.0049 781.031389.1641
Module end 'content' 0.01640.0023 870.195330.3047
Script end 0.0187  900.5000 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003016.1821140.0002
Check MTime0.00126.3417140.0001
Mysql Total
Database connection0.00094.837110.0009
Mysqli_queries0.004021.441630.0013
Looping result0.00000.100210.0000
Template Total0.00199.910.0019
Template load0.00115.676910.0011
Template processing0.00084.122910.0008
Override
Cache load0.00073.687810.0007
General
dbfile0.00031.702480.0000
String conversion0.00000.063440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs