eZ Community » Forums » Setup & design » Please help assigning value to a...
expandshrink

Please help assigning value to a variable - not working properly

Please help assigning value to a variable - not working properly

Thursday 01 May 2003 11:49:22 pm - 2 replies

I am using the code below in a template. the purpose is to only display certain folders based on the partent folder at the root level. At the root level each parent folder is in a unique section.

I am going out and getting all section and node values for the content of node_id=2 and comparing to the section id of the page that is currently displayed ( So if you are viewing a folder 4 levels deep (node_id=287 section_id=3) the script will return the node_id (node_id=234 and section_id =3) of the 1st level folder in that section at the content level node_id=2.

Whilst viewing a page with a node_id=287 the script sets the variable top_cat =24 (default incase of a folder not assigned to a cestion or some other error) then goes out and returns the node_id of the root parent which is 234 (this value is correct and then should assign this value to top_cat. It then displays the current value of top_cat.

The out put I am getting is
!24!
[234]
=24=
*24*

The output I expected is
!24!
[234]
=234=
*234*

the problem seems to be in the assignment of the {set top_cat=....}

Can Anyone help me please - I have tried everything I can think of

jonathan

<tr>

<td class="menuitem">
{* Set your top category here *}
{let top_cat=24
used_node=false()
menu_css=5
menu_css_active=6}
!{$top_cat}!
{let name=Child children=fetch('content','list',hash(parent_node_id,2))}
{section loop=$:children}
{section show=eq($Child:item.object.section_id,$DesignKeys:used.section)}
{set top_cat=$Child:item.node_id}
[ {$Child:item.node_id} ]
= {$top_cat} =
{/section}
{/section}
{/let}
{* Set your top category here *}
*{$top_cat}*
{/let}
</td>
</tr>

Friday 02 May 2003 11:52:20 am

Jonathan,

Can't really explain why, but the problem lies with the fact that you name the second {let}. I changed your code to the following, and that works.

{let top_cat=24
used_node=false()
menu_css=5
menu_css_active=6}
!{$top_cat}!
{let children=fetch('content','list',hash(parent_node_id,2))}
{section loop=$:children}
{section show=eq($:item.object.section_id,$DesignKeys:used.section)}
{set top_cat=$:item.node_id}
[ {$:item.node_id} ]
= {$top_cat} =
{/section}
{/section}
{/let}
{* Set your top category here *}
*{$top_cat}*
{/let}

As you can see, I removed the name 'Child' from the second {let} and the loop items (you could even remove the whole second let and place the fetch in the section, i.e. loop=fetch(...)).
Anyway, as said, the above works for me. Now I'm gonna look a bit closer at namespaces.....
Greetz,

Vivienne

Friday 02 May 2003 1:34:56 pm

Thanks for the help - I had about 10 different verions of the same coded - all with minor differences - all returned the same problem in terms of not setting the value.

Thanks for the info on the {section=name loop=fetch()} I have use it before but I felt my above example was the clearest in terms of "full" code with no short cuts.

Maybe someone at ez publish or one of the other members of this forum can explain the problem in my original code and post some more info about the namespaces.

Jonathan

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from