This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Developer » Weird error

Weird error

Weird error

Wednesday 22 April 2015 9:07:41 pm - 2 replies

From the provided code I get the error "

Warning: eZTemplate:set Apr 22 2015 20:57:18
Variable 'Child:counter' doesn't exist, cannot set

" and the counter does not run, it is stuck at 1. Heres the code:

{def $counter = 1}
  {section loop=$:children)}

 {if eq($counter, 1)}


 <td>1:{$counter} <a href={$:item.url_alias|ezurl}>{attribute_view_gui align=left image_class=articlethumbnail attribute=$:item.object.data_map.image}<\/a></td>

 {set $counter = inc($counter)}

 {* set $counter=2 *}1:E:{$counter}

 {elseif eq($counter, 2)}

 <td>2:{$counter} <a href={$:item.url_alias|ezurl}>{attribute_view_gui align=left image_class=articlethumbnail attribute=$:item.object.data_map.image}<\/a></td>

 {set $counter=3}

 {elseif eq($counter, 3)}

 <td>3:{$counter} <a href={$:item.url_alias|ezurl}>{attribute_view_gui align=left image_class=articlethumbnail attribute=$:item.object.data_map.image}<\/a></td>

 {set $counter=inc( $counter )}   

 {elseif eq($counter, 4)}       

 <td>4:{$counter} <a href={$:item.url_alias|ezurl}>{attribute_view_gui align=left image_class=articlethumbnail attribute=$:item.object.data_map.image}<\/a></td>       


 {set $counter=1}   




{undef $counter}


Any ideas anyone?

Modified on Wednesday 22 April 2015 9:21:02 pm by Atle Enersen

Thursday 23 April 2015 8:40:31 am

Hello Atle,

The first problem I see is that your using deprecated template language constructs (introduced in eZ Publish 3, very old) like section, which you should not use.

Instead you should use the foreach or for constructs as replacements for section looping:

If you were not using section, I do not think you would be having problems, I'm almost certain. Which in part is why I strongly encourage you to rewrite your template code (in question) to not use the deprecated section construct.

If ... you will not rewrite to use foreach instead of section, for whatever reason (hint: section seems cool or nerdy to use but it's not, lol) then you should remember that section (as my doc link shows) was meant to be used with let instead of def. If you were using let instead of def, I'm almost certain you would not have the error in question.

But all of this old syntax research I did for my reply brings up the question, why are you trying to manually increment the loop counter your self at all?

section has always provided iteration index / counter variable by default which I would also encourage you to use instead of trying to write needed template code yourself to do what is already being done and provided to you (as I see no advantage in the code you share to doing this yourself in custom code).

Here is an example of how that works:

{let elements=array('element1', 'element2', 'element3', 'element4', 'element5')}
{section loop=$elements}
   Element value : {$:item}<br/>
   index : {$:index}<br/>
   number : {$:number}<br/>
   key : {$:key}<br/>

In short, use '{$:index}' for your counter variable in your if conditional blocks and don't bother incrementing it happy.gif Emoticon

I hope this helps!


Thursday 23 April 2015 9:04:10 am

Hello Heath and thanks again, that did the job happy.gif Emoticon

Will have to rewrite it to avoid deprecated syntax, but that is managable happy.gif Emoticon


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

36 542 Users on board!

Forums menu

Proudly Developed with from