zotonic 0.7.1:
from within a template, how can i get the children of the current
page, as defined in the main_menu?
Example for the main_menu:
1: {% print m.rsc.main_menu.menu %}
2: {% print m.rsc.main_menu.menu|menu_flat %}
Sample output:
1: [{360,[]},{316,[{314,[]},{315,[]}]}]
2: [{360,[1],undefined},
{316,[2],down},
{314,[1,2],undefined},
{315,[2,2],undefined},
{undefined,undefined,up}]
Which you the may traverse with a for loop, looking for you current
id, and the from there you have the children...
I leave it as an exercise... ;c)
//Andreas
2011/12/5 93-interactive <93inte...@googlemail.com>:
On Dec 6, 11:38 am, Andreas Stenius <andreas.sten...@astekk.se> wrote:
> You can get the complete menu structure from the menu property of a
> menu resource.
>
> Example for the main_menu:
>
> 1: {% print m.rsc.main_menu.menu %}
> 2: {% print m.rsc.main_menu.menu|menu_flat %}
>
> Sample output:
>
> 1: [{360,[]},{316,[{314,[]},{315,[]}]}]
>
> 2: [{360,[1],undefined},
> {316,[2],down},
> {314,[1,2],undefined},
> {315,[2,2],undefined},
> {undefined,undefined,up}]
>
> Which you the may traverse with a for loop, looking for you current
> id, and the from there you have the children...
> I leave it as an exercise... ;c)
thank you, unfortunately i still have trouble understanding it, i
should mention, that i am new, both to erlang and zotonic.
As i understand it, result 2 gives me all available id's in list
position [1] and the position within result 1 in list position [2]
(reverse).
So i have two problems here. Result 2 gives me numbers, whereas result
1 gives me names where available and numbers where not, so i can not
match all entries.
Example from my site:
1)
[{page_home,[]},{page_about,[]},{page_contact,[]},{331,[{336,[]},{332,
[]}]}]
2)
[{312,[1],undefined},
{313,[2],undefined},
{314,[3],undefined},
{331,[4],down},
{336,[1,4],undefined},
{332,[2,4],undefined},
{undefined,undefined,up}]
Even if i could, i would still have the problem that i have a reverse
position list, e.g. [1,2] for 314, which within the template, i do not
know how to apply to get the children from result 1.
1)
[{316,[{318,[]},{319,[]}]},{317,[]}]
2)
[{316,[1],down},
{318,[1,1],undefined},
{319,[2,1],undefined},
{undefined,undefined,up},
{317,[2],undefined}]
So what i have so far:
{% for page,pos,rest in m.rsc.main_menu.menu|menu_flat %}
{% if page /= undefined %}
{{ page }} on {{ pos }} <br />
{% endif %}
{% endfor %}
what i would need now in instead the {{ page }} on {{ pos }} line
something like
m.rsc.main_menu.menu[pos]
That gives me the children, but i did not find a way to achieve this,
any ideas?
So, to only include the children of the current page (if any), you
could do something along the lines of (assuming the current page id is
in variable "id"):
{% for page_id, path, action in m.rsc.main_menu.menu|menu_flat %}
{% if id = page_id and action = "down" %} {# no children unless
action is down #}
{% endif %}
{% endfor %}
Hmm... this becomes quite hard to do with only templating... why not
write a simple filter to return just the children of a given id?
What end result are you looking for?
I didn't quite understand your intention with "m.rsc.main_menu.menu[pos]".
//Andreas
2011/12/7 93-interactive <93inte...@googlemail.com>:
On Dec 7, 1:43 pm, Andreas Stenius <andreas.sten...@astekk.se> wrote:
> Hmm... this becomes quite hard to do with only templating... why not
> write a simple filter to return just the children of a given id?
because i am new and don't know how to do things on zotonic ;-)
Changed it to filter, got it work, thank you.
Cool :-)