Forums / Developer / Custom Tool Trouble

Custom Tool Trouble

Author Message

Fraser Hore

Tuesday 13 December 2005 2:19:24 am

I've created a new tool for the right toolbar to show related items based on a keywords attribute in the node object being viewed. I've also added a condition to show the toolbar only if there is a keywords attribute that is set.

With a clear cache, the toolbar shows up when there are set keywords, it displays related items as intended, and clicking on an item takes you to its page. Let's say we clicked on item A in the toolbar and we are looking at item A's page. We can click on item B in the toolbar and go to item B's page. Now, if we click on item A's link in the toolbar again, we go to item A's page but there is no toolbar! The toolbar will never appear on item A's page again until we clear the cache. I suppose that it must have something to do with view caches but i'm not very familiar with how these work. Any suggestions would be much appreciated!

Here's the code in the tool template:

{* Toolbar - Related *}
{if is_set($node.object.data_map.keywords.content)}
<div class="toolbar-item {$placement}">
{def $related_nodes=$node.object.data_map.keywords.content.related_nodes}
<div class="toollist">
<div class="toollist-design">
<h2>{$title}</h2>
<div class="content-view-children">
{foreach $related_nodes as $related_node}
<p>{node_view_gui view=listitem content_node=$related_node}</p>
{/foreach}
</div>
</div>
</div>
</div>
{/if}
{undef $related_nodes}

Cheers,

Fraser

Bruce Morrison

Tuesday 13 December 2005 3:03:28 am

Hi Fraser

I think this is an with the cache. When you first view he page after the cache has been cleared $node is set. On the second viewing the cached version of the page is used. In the cached version $node is not retrieved (and not set) - this is the purpose of the cache, to save unnecessary database access. Of course this doesn't help you much ;)

If you are viewing a page with a node (pages like search results or the shop do not have a node_id) you will have to retrieve it first.

{* Toolbar - Related *}
{if is_set($module_result.content_info)}
  {def $current_node = fetch(content,node,hash(node_id,$module_result.content_info.node_id))}
  {if is_set($current_node.object.data_map.keywords.content)}
<div class="toolbar-item {$placement}">
    {def $related_nodes=$current_node.object.data_map.keywords.content.related_nodes}
<div class="toollist">
<div class="toollist-design">
<h2>{$title}</h2>
<div class="content-view-children">
      {foreach $related_nodes as $related_node}
<p>{node_view_gui view=listitem content_node=$related_node}</p>
      {/foreach}
</div>
</div>
</div>
</div>
    {undef $current_node}
  {/if}
  {undef $related_nodes}
{/if}

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Fraser Hore

Tuesday 13 December 2005 5:42:44 am

Your code works great! Thanks a lot Bruce! I appreciate your help.

I'm still a litte confused as to why the node isn't available in the tool template. When i use my old code in the node/view/full template it works fine.

Fetching the node in the tool template did seem to slow things down a bit.

Cheers,

Fraser