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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 01:32:24
Script start
Timing: Jan 31 2025 01:32:24
Module start 'layout'
Timing: Jan 31 2025 01:32:24
Module start 'content'
Timing: Jan 31 2025 01:32:24
Module end 'content'
Timing: Jan 31 2025 01:32:24
Script end

Main resources:

Total runtime0.0272 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 588.0313151.1953
Module start 'layout' 0.00480.0041 739.2266220.6563
Module start 'content' 0.00890.0165 959.88281,001.8984
Module end 'content' 0.02540.0017 1,961.781333.9922
Script end 0.0271  1,995.7734 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00269.7259140.0002
Check MTime0.00114.0358140.0001
Mysql Total
Database connection0.00103.763910.0010
Mysqli_queries0.00217.822530.0007
Looping result0.00000.103510.0000
Template Total0.00114.110.0011
Template load0.00093.300710.0009
Template processing0.00020.809610.0002
Override
Cache load0.00062.325310.0006
General
dbfile0.00030.971980.0000
String conversion0.00000.037740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs