Forums / Setup & design / Sitemap customization

Sitemap customization

Author Message

Terry Grossman

Sunday 25 July 2004 8:21:51 am

Hey Folks,

I really like the sitemap auto-generated from the content tree, but I have pieces I wished to hide from the users. My solution was to use an override on sitemap.tpl that skips over content whose name begins with a certain character.

I know this is a bit of a hack, and a better approach would be to extend the content class and add a field that specifies visibility, but this way was very easy to do, and anyone familiar with *NIX will be familiar with "hidden" files/folders beginning with "."

I used "-" as the flag for hiding content from sitemap so that it would be obvious in the admin view which areas were not visible to the users.

Unfortunately, in order to hide the "Media Files" folder, (at least in ver 3.4) you have to manually change the entry in ezcontentobject_name since the admin view won't let you modify it.

Following the code there are some notes about a bug I don't understand...

{* SITEMAP override template. This TPL hides content that begins with a special char *}
{let page_limit=10
     col_count=2
     curr_count=0
     children=fetch('content','list',hash(parent_node_id,$node.node_id,limit,$page_limit,offset,$view_parameters.offset))
     child_count=fetch('content','list_count',hash(parent_node_id,$node.node_id))}

<div class="maincontentheader">

<h1>{"MySite Site map"|i18n("design/standard/node/view")} </h1>
</div>

<table width="100%" cellspacing="0" cellpadding="4">
<tr>
{section name=Child loop=$children}

  {* only show items whose name does not begin with a dash *}
  {section show=$Child:item.name|begins_with( "-" )|not }


    {* increment the table content counter *}
    {set curr_count=inc( $curr_count )}

    <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>

    {* move to the next table row if we've filled up the current one with data*}
    {section show=mod($curr_count, $col_count)|eq(0)}
</tr>
<tr>
    {/section}

  {/section}

{/section}
</tr>
</table>
{/let}

The standard sitemap.tpl uses the "delimiter modulo" construct to determine when to inject a "</tr><tr>" into the HTML to ensure the content gets put into columns correctly. In order to get that to work I introduced a variable curr_count which only gets incremented when a content section is visible. It is this variable which is checked, rather than the current loop iteration, in order to determine when the TR tags should be added. This doesn't work for some reason, and I'm not sure why -- debug code showed that curr_count was never being incremented and always remained 0 throughout all the loops. Suggestions?

Terry

Terry Grossman

Sunday 25 July 2004 8:23:46 am

I probably should have mentioned that because of the bug, this template only produces a single column

T.