Forums / Setup & design / Sitemap with more than 2 levels depth

Sitemap with more than 2 levels depth

Author Message

Andreas Tremel

Saturday 03 February 2007 7:28:13 am

Hello community,

my EZ publish 3.8.4 displays a sitemap at: http://www.site.domain/content/view/sitemap/2

This thread asks how to increase the depth of the sitemap tree:
http://ez.no/community/bugs/site_map_doesn_t_show_all_the_objects

However, no solution is provided.
I would greatly appreciate a solution that displays all levels availiable dynamically.
Does anybody know how to do this?

Thank you in advance!

Regards,
Andreas Tremel

Felix Woldt

Sunday 04 February 2007 1:49:34 am

Hallo,

i think you have to create your own sitemap.tpl. In this template you create your own fetches to display your sitemap with special depth.

tip: if you want to have your sitemap link in ne normal navigation of ez, create a dummy contentobject with name sitemap and create an override template for the view 'full' of this object. In this template you write your own fetches to display your custom sitemap.

best regards
Felix

http://www.jac-systeme.de - Developers united in eZ Publish: http://www.cjw-network.com

CJW Newsletter 1.0.0 released: http://projects.ez.no/cjw_newsletter

Andreas Tremel

Sunday 04 February 2007 6:16:03 am

Hello Felix,

thank you, that helped me to find the code. Strangely the sitemap function it is located in the design folder... but anyway.

I made a copy in:
\design\my_siteaccess\override\templates\node\view\sitemap.tpl

It works, changes to the file are now applied. However, the more callenging part is how to modify the code block:

This is the standard code:

{section name=Child loop=$children}
    <td>
    <h2><a href={$Child:item.url_alias|ezurl}>{$Child:item.name}</a></h2>

    {let sub_children=fetch('content','list',hash(parent_node_id,$Child:item.node_id,limit,$page_limit))
         sub_child_count=fetch('content','list_count',hash(parent_node_id,$Child:item.node_id))}

    <ul>
    {section name=SubChild loop=$:sub_children}
    <li><a href={$:item.url_alias|ezurl}>{$:item.name}</a></li>
    {/section}
    </ul>

    {/let}

    </td>
    {delimiter modulo=$col_count}
</tr>
<tr>
    {/delimiter}
{/section}

That looks like a nested loop. I suppose "let" is the function that performs a loop. However, the doc says "let" is deprecated, give no hint or clue what to use instead:
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_functions/variables/let

I'm stuck. I don't know how to modify the loop to display more than 2 levels. Can anyone help?

Regards,

Andreas Tremel

Claudia Kosny

Sunday 04 February 2007 12:57:30 pm

Hi Andreas

'let' was used for declaring variables, not for looping. The looping in your code is done with

{section name=... loop=...} 
 ...
{/section}

which is also deprecated.
A better way to loop through something is 'foreach'. Take this part of your code:

{section name=SubChild loop=$:sub_children}
 <li><a href={$:item.url_alias|ezurl}>{$:item.name}</a></li>
{/section}

This means: Loop through the variable $:sub_children (which is an array) and display the url_alias and the name of each item in this variable. The name of the section is not used in this example, as far as I know it was used to provide a namespace for the variables within the loop (not sure though, I did not use section much).
The same code using the foreach syntax would be:

{foreach $:sub_children as $sub_child}
 <li><a href={$sub_child.url_alias|ezurl}>{$sub_child.name}</a></li>
{/foreach}

which is very similar to the PHP foreach. The variable $:subchildren came from the outer loop and must be adapted if you change the outer loop as well.

I am not sure what to do about the sitemap. If you fetch all nodes on all levels at the same time you might get major performance problems as soon as your website has a certain size. Apart from that is not so easy to do from within the template language (as you certainly have found out by now).
A nice idea might be to expand only one node while not changing the rest of the sitemap. This can be done easily with javascript and ajax (although you would need to write your own module for that this would be fairly easy to do). I don't have a good idea how to do this without javascript though - maybe you could (ab)use the treemenu operator for this?
So I would circumvent the problem by changing the sitemap so that each node has an additional link which links to the sitemap seen from this node. Of course then each sitemap also needs a link to the next level up to come back to the previous view. Although you will not see all levels at the same time, you can easily navigate between the different levels.

Good luck

Claudia

André R.

Sunday 04 February 2007 2:35:33 pm

The performance issue could be tackled with turning of view_cache with:

{set-block scope=root variable=cache_ttl}0{/set-block}

in the top of the sitemap template, and use one cache block instead like this:

{def $current_user = fetch( 'user', 'current_user' )}
       $user_hash = concat($current_user.role_id_list|implode( ',' ), ",", $current_user.limited_assignment_value_list|implode( ',' ))}
{cache-block  keys= $user_hash expiry=15000 ignore_content_expiry}
-- output --
{/cache-block}

The multi level depth issue could easily be solved by doing it recursivly, include a template the does one level at a time and and that template calls itself foreach children containers with children. Look at show_content_structure.tpl in admin design or the one in ezjaxx.

But you really should have a limit on number of levels you show, if it gets to big and complex it looses the point of having a sitemap in the first place. Getting a quick overview, and higlight the structure.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Claudia Kosny

Sunday 04 February 2007 2:51:28 pm

Hi André

You are right - using a template that includes itself is a real simple way to do display all levels. I totally forgot about this.
I am interested in your choice of cache parameters though as I would have used expiry=0 and done without the ignore_content_expiry. The way I understand the cache this would create the sitemap and only update it if there is a change in the content, in which case a full sitemap should be updated in any case. You as a eZ crew member certainly know more about it so I would appreciate telling me your reasons.

Thanks

Claudia

André R.

Monday 05 February 2007 3:16:43 am

ignore_content_expiry:
This is just a personal preference for speed.
If you want the site map to always be current it is not an option.

But with unlimited site map depth, this page could potentially be a bit slow.
Thats why I suggested such an aggressive caching

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Xavier Dutoit

Monday 05 February 2007 6:35:23 am

Hi,

I'd suggest to test the depth and not go too deep, because every single article/file whatever content shouldn't be in the sitemap anyway.

Alternatively, only displays the nodes that contains sub-items (ie. not the final leaves), that might be better.

As for the speed, don't fetch the children nor the child counts (you don't need it anyway) and foreach on the .children attributes. Based on my discussion with Kristof this week-end and an analyis, it doesn't prefetch each attribute on the .children, but does for the fetch list.

See the suggestion so fetch list can be as quick as children
http://issues.ez.no/10164
X+

http://www.sydesy.com

André R.

Tuesday 06 February 2007 1:06:44 am

Well articles / products / events / images.. and such kind of content should not be displayed in the sitemap.

X:
Another but minor enchantment for content list/tree fetch:
http://issues.ez.no/IssueView.php?Id=10168&activeItem=5

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom