Forums / Setup & design / Is this a variable scope bug or just something I don't understand properly?

Is this a variable scope bug or just something I don't understand properly?

Author Message

Tristan Koen

Monday 11 August 2003 1:10:27 am

Hi All,

I have run into a very strange "bug" that I am at a loss to explain.

I have a {section name=Folder loop=...}. Within this section, I have access to a number of objects, including the 'item' object from the current iteration of the loop. For example, within the section I have a line:
<h1>{$Folder:item.name}</h1>
Which shows the name of the object. This works perfectly.
The problem comes in when I have a {let} or {section} embedded within the current {section} scope.
In any code following the embedded {/section}{/let} , I appear to lose all my objects - even though they remain in scope - EXCEPT for the LAST iteration of the loop which works.

The debug message I get is:
Unknown template variable 'item' in namespace 'Folder'

The offending line is the message below is:
<a href={concat('content/view/full/',$:item.node_id)|ezurl}>[ Read more about {$Folder:item.name}... ]</a>
</div>

If I move the offending line to a position before the embedded {let} it works as it should. Very odd...

Can anyone shed some light on this?

The full source code follows:

{let folder_list=fetch(content,list,hash(parent_node_id,47,
sort_by,array(array(priority))))}
{section name=Folder loop=$folder_list} ******** SECTION DECLARATION ********
<div class="columnItem">
<h1>{$Folder:item.name}</h1> ******** IN SCOPE; WORKS FINE ********
{let item_list=fetch(content,tree,hash(parent_node_id,$Folder:item.node_id,
class_filter_type,exclude,
class_filter_array,array(1),
sort_by,array(array(published,false()))))}
{section loop=$Folder:item_list}
<h2>{$:item.data_map.title.content}</h2>
{$:item.data_map.intro.content.output.output_text}
<p><a href={concat('content/view/full/',$:item.node_id)|ezurl}>[ Read More... ]</a></p>
{/section}
{/let}
<a href={concat('content/view/full/',$:item.node_id)|ezurl}>[ Read more about {$Folder:item.name}... ]</a> ******** SHOULD BE IN SCOPE. FAILS COMPLETELY EXCEPT FOR LAST ITERATION ********
</div>
{/section}
{/let}

Paul Borgermans

Monday 11 August 2003 10:17:06 am

I have had also variable scoping bugs with nested {section}{/section}

Definately something that needs to be checked. Or maybe I'll be wiser after the course next week and suffer from misunderstanding currently.

-paul

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

Tristan Koen

Tuesday 12 August 2003 1:26:20 am

Thanks for the confirmation Paul. I have filed a bug report.