Forums / Install & configuration / static cache - generate sibling node

static cache - generate sibling node

Author Message

stephane couzinier

Friday 23 February 2007 5:56:05 am

I need to find away to generate the sibling node of an object.
In 1 folder I have 3 articles, on each article page I put:
- 2 links next and previous news.
- the position of the news
On the first news I have only 1 link Next news
On the last there is only the link Previous news.

don't flush the cache

Betsy Gamrat

Saturday 24 February 2007 8:06:48 am

Hi,

I did something similar on http://www.thepulsenetwork.com/healthcare_news/breaking_news_nursing/institute_for_johns_hopkins_nursing_to_offer_nurse_practitioner_continuing_education/(item)/3.

I added an additional view parameter to the folder template, called <b>item</b>. If <b>$view_parameters.item</b> is set, the folder displays that item (for example the fourth child), and the navigation displays options to view the previous item, the list, or the next item. It will observe the number of children in the list - so previous and next are only displayed if they are valid.

At the top of <b>full_folder.tpl</b>, I added the following code. It uses <i>(item)/4</i> to indicate that it is supposed to display the fourth child of the folder. As you can see, instead of displaying the folder contents, it displays the requested node.

{if is_set($view_parameters.item)}
            {node_view_gui content_node=fetch_alias( children, hash( parent_node_id, $node.node_id,
                                                             offset, $view_parameters.item,limit,1,
                                                             sort_by, $node.sort_array)).0 item=$view_parameters.item view=full}
{else}

The site has a sub_navigation template, which provides navigation in the lefthand column, and is included into <b>pagelayout.tpl</b>. It will list all the children of a node, unless there is an <b>item</b>, in which case, it provides the item relative navigation. One note, the content class this is running with is <i>rss</i>. Be sure to change that to work on your site. Substitute your content class name for <i>rss</i>.

{if $node_id|ne(false)}
	{def $item_parm=-1 $item_parm_flag=false()}
	{if is_set($view_parameters.item)}
		{set $item_parm=$view_parameters.item}
		{set $item_parm_flag=true()}
                                {set-block scope=root variable=cache_ttl}0{/set-block}
	{/if}
	{def $n=''}
	{if $module_result.content_info.parent_node_id|ne(2)}
		{if and($module_result.content_info.class_identifier|eq('folder'),$item_parm_flag)}
			{set $n=$module_result.content_info.node_id}
		{else}
			{set $n=$module_result.content_info.parent_node_id}
		{/if}
	{else}
		{set $n=$module_result.content_info.node_id}
	{/if}
	{def $node_data=fetch(content,node,hash(node_id,$n))}
        <h2>{$node_data.name}</h2>
        <div class="pp_subnavitem">
	{if and($module_result.content_info.class_identifier|ne('rss'),not($item_parm_flag))}
		{def $list_items=fetch_alias( children, hash( parent_node_id, $n,'sort_by',array('priority',true())))}
		{def $list_count=fetch_alias( children_count, hash( parent_node_id, $n ) )}
                	{section var=child loop=$list_items}
				{if $child.node_id|ne($node_id)}
					{if $child.object.class_identifier|ne('link')}
						<a href={$child.url_alias|ezurl} title="{$child.name}">{$child.name}</a>
					{else}
						<a href={$child.data_map.location.content|ezurl} title="{$child.name}">{$child.name}</a>
					{/if}
				{else}
					<p>{$child.name}</p>
				{/if}
	               	{/section}
	{else}
		{if $item_parm_flag}
			{def $item_offset=0}
			{if $item_parm|gt(0)}
				<a href={$node_data.url_alias|concat('/(item)/',$item_parm|dec)|ezurl} title="Previous article">Previous Article</a>
			{/if}
			{if $item_parm|gt(10)}
				{set $item_offset=$view_parameters.item|mod(10)}
				{set $item_offset=$view_parameters.item|sub($item_offset)}
			{/if}
			<a href={$node_data.url_alias|concat('/(offset)/',$item_offset)|ezurl} title="Return to listing page">Article List</a>
			{if $node_data.children_count|dec|gt($item_parm)}
	                        <a href={$node_data.url_alias|concat('/(item)/',$item_parm|inc)|ezurl} title="Next article">Next Article</a>
			{/if}
		{/if}

	{/if}
	{undef $item_parm $item_parm_flag $item_offset $n $node_data}
	</div>
{/if}