Share » Forums » Developer » Using let/set within namespaces

Using let/set within namespaces

Using let/set within namespaces

Wednesday 23 April 2003 5:17:51 am - 9 replies

Modified on Wednesday 23 April 2003 5:20:32 am by Paul Forsyth

Author Message

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

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

36 542 Users on board!

Forums menu