Forums / Developer / Using let/set within namespaces

Using let/set within namespaces

Author Message

Paul Forsyth

Wednesday 23 April 2003 5:17:51 am

Im trying to use some logic that sets a variable from within a section call.

{let found_something=0}

{section name=Something loop=$my_array}
{set found_something=1}
{/section}

{$found_something}

When run {$found_something} outputs '0', and I receive the error:

Warning: eZTemplate:set Apr 23 2003 13:12:37

Variable 'Something:found_something' doesn't exist, cannot set

This sounds logical since the variable is within another namespace.

If i try to specify the namespace then i receive an invalid characters error. I guess let/set dont like $ chars in there...

Can i alter a variable from one namespace from within another namespace?

This example is simplistic. My real use is more complex and requires a global variable to be changed from within multiple section calls. Is it possible to be shown an example of this working?

thanks

Paul

Sergiy Pushchin

Wednesday 23 April 2003 5:23:13 am

Better way to do it:
{let name=Something found_something=0}
{section loop=$my_array}
{set found_something=1}
{/section}
{$found_something}
{let}

In that case all variables in the same namespace.

Paul Forsyth

Wednesday 23 April 2003 5:37:55 am

Thanks Sergiy,

I had read the doco on using {let name=...} but earlier that caused problems with my three nested sections(!). But, i manged to get it working using a single namespace, though it does ruin the namespace structure somewhat...

Paul

Paul Borgermans

Wednesday 23 April 2003 6:17:42 am

Had a similar problem when enhancing the forum templates.

A variable available (created) in an outer section appears to be invisible for an inner section (loop). Not sure if the bug is in my head and template code or in ez publish. I am studying the docs and code again to find out more about variable scoping and nested sections.

The weird thing is that a simple variable seems to work, a complex one (object) not.

Paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Jan Borsodi

Thursday 24 April 2003 6:25:50 am

As the template engine is today all reads are done using the root namespace of the file while writes are using the current namespace. To overcome the problems you have to move the namspace as Sergey noted.

Future versions of the template engine will probably support namespace declarations in function input variables as well as relative namespace references.

Some examples:
{set #:found_something=1}
sets the found_something variable in the root namespace
{set ..:found_something=1}
sets the found_something variable one namespace up
{$..:found_something}
Accesses the found_something variable one level up from the current namespace

Also another way to use section would help out, something like:
{section variable=i loop=$items}
{$:i.key} - {$:i.item.name}
{section variable=j loop=$:i.item.children}
{$:j.item}
{/section}
{/section}
Here the template loop variables are set as an hash array in the current namespace.

Last a new way to do if/else-if/else style checks.
{section show=eq($a,$b)}
{section-else show=eq($a,$c)}
{section-else show=eq($a,$d)}
{section-else}
{/section}

Nothing has been decided yet so please come with suggestion for things you would like to see in the template engine (not just namespaces).

--
Amos

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

Paul Borgermans

Friday 25 April 2003 5:48:40 am

>Nothing has been decided yet so please come with suggestion
>for things you would like to see in the template engine (not
>just namespaces).

A range operator for creating/slicing arrays (like in php) would be nice.

More will come as we learn/work with the templates (still a steep learning curve)

Paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Chris Winchester

Wednesday 28 May 2003 10:33:47 am

An "explode" function would be useful - I want to split the path_string attribute on the '/' character into an array so I can easily access the node_id's of the ancestors of a particular node without having to loop up the tree. (I'm currently doing this and building a linked list of arrays within arrays, which is pretty resource intensive - and consequently a bit frustrating given that the information's already there in path_string!!)

Of course I may be missing something as I'm still very new to this! (are there any string handling functions apart from concat?) If I've missed the point, please do put me straight.

I'll post up the code I'm currently using once I'm sure it's all working. I had some trouble with namespaces, but this is now resolved thanks to Sergiy and Jan :)

Cheers
- Chris

Paul Forsyth

Thursday 29 May 2003 2:27:38 am

btw, do multiple section-else statements work?

I have:

{section show=$search_count|gt(1)}
{$search_count} things found.
{section-else show=eq($search_count, 1)}
1 thing found.
{section-else}
No things found.
{/section}

but when $search_count is 0 both lines within the section-else statements are used, giving me:

1 thing found. No things found.

Currently using stable branch rev 2450.

Chris Winchester

Thursday 29 May 2003 7:49:17 am

I had the same problem Paul. Try nesting them instead:

{section show=$search_count|gt(1)}
{$search_count} things found.
{section-else}
{section show=eq($search_count, 1)}
1 thing found.
{section-else}
No things found.
{/section}
{/section}

Paul Forsyth

Thursday 29 May 2003 9:31:41 am

thanks chris,

yes, that works. ive used nested sections before though it can lead to some horrible code!

ive just noticed that the multiple section-else shows are possible future additions to the template engine... oops :)

btw, the explode function could be made by adding an operator that exposes the appropriate php function to the template engine. its not difficult to do. also, iirc, 3.1 allows you to do this from the admin interface?

paul

eZ debug

Timing: Jan 18 2025 02:55:42
Script start
Timing: Jan 18 2025 02:55:42
Module start 'content'
Timing: Jan 18 2025 02:55:43
Module end 'content'
Timing: Jan 18 2025 02:55:43
Script end

Main resources:

Total runtime1.0941 sec
Peak memory usage4,096.0000 KB
Database Queries221

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 587.7109180.8359
Module start 'content' 0.00590.9646 768.5469750.9922
Module end 'content' 0.97050.1235 1,519.5391344.4375
Script end 1.0940  1,863.9766 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00410.3732210.0002
Check MTime0.00160.1477210.0001
Mysql Total
Database connection0.00050.048410.0005
Mysqli_queries0.995290.96182210.0045
Looping result0.00200.18132190.0000
Template Total1.068897.720.5344
Template load0.00310.281620.0015
Template processing1.065797.402920.5329
Template load and register function0.00010.012510.0001
states
state_id_array0.00080.077610.0008
state_identifier_array0.00100.090420.0005
Override
Cache load0.00280.25511080.0000
Sytem overhead
Fetch class attribute can translate value0.00150.135460.0002
Fetch class attribute name0.00160.1424130.0001
XML
Image XML parsing0.00390.352760.0006
class_abstraction
Instantiating content class attribute0.00000.0027140.0000
General
dbfile0.00710.6513410.0002
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
10content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
17content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
9content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 42
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs