Get current node within an operator

Author Message

Jérôme Vieilledent

Thursday 26 June 2008 1:57:26 am

Hello,

I would like to know if it was possible to get the current viewed node in a template operator, such as we do with the $node variable in a template.
I guess this variable is registered somewhere and accessible with PHP code but how ?

Thanks by advance

André R.

Thursday 26 June 2008 7:40:38 am

Look in the first parameter in your modify function on the template operator class ( $tpl ).

Example code (if in pagelayout):

                    if ( $tpl->hasVariable('module_result') )
                    {
                       $moduleResult = $tpl->variable('module_result');
                    }

                    if ( $tpl->hasVariable('current_node_id') )
                    {
                       $currentNodeId = (int) $tpl->variable('current_node_id');
                    }
                    else if ( isset( $moduleResult['node_id'] ) )
                    {
                       $currentNodeId = (int) $moduleResult['node_id'];
                    }
                    else if ( isset( $moduleResult['path'][count( $moduleResult['path'] ) - 1]['node_id'] ) )
                    {
                       $currentNodeId = (int) $moduleResult['path'][count( $moduleResult['path'] ) - 1]['node_id'];
                    }

if in node template just use the $node variable.

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

Jérôme Vieilledent

Thursday 26 June 2008 7:54:42 am

Thanks André !

So we can access to the current node with this :

print_r($tpl->Variables['']['node']);

André R.

Thursday 26 June 2008 7:57:41 am

To print the current node id:

$node = $tpl->variable('node');
print_r( $node->attribute('node_id') );

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

Jérôme Vieilledent

Thursday 26 June 2008 8:29:33 am

You're right, that's much cleaner :-D

yunxia cai

Tuesday 20 April 2010 7:34:12 pm

Hello!

  I have a question.

 first:I define the {def $current_node= fetch( content, node, hash( node_id, $current_node_id ) ) }

 then if the class is not folder ,I need define the $current_node

if I define again  {def $current_node= fetch( 'conten't, 'list', hash( 'parent_node_id', $node.parent_node_id ) ) }

and ,the  $current.node.module_result.content_info.object_id is right?

Thanks! 

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 18 2025 11:24:46
Script start
Timing: Jan 18 2025 11:24:46
Module start 'layout'
Timing: Jan 18 2025 11:24:46
Module start 'content'
Timing: Jan 18 2025 11:24:47
Module end 'content'
Timing: Jan 18 2025 11:24:47
Script end

Main resources:

Total runtime0.6075 sec
Peak memory usage4,096.0000 KB
Database Queries68

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 589.0547152.6250
Module start 'layout' 0.00550.0031 741.679739.4453
Module start 'content' 0.00860.5973 781.1250628.4375
Module end 'content' 0.60600.0015 1,409.562516.1563
Script end 0.6075  1,425.7188 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.6352160.0002
Check MTime0.00130.2208160.0001
Mysql Total
Database connection0.00110.177010.0011
Mysqli_queries0.540889.0159680.0080
Looping result0.00080.1274660.0000
Template Total0.574494.620.2872
Template load0.00240.399820.0012
Template processing0.572094.150020.2860
Template load and register function0.00010.016410.0001
states
state_id_array0.00120.195110.0012
state_identifier_array0.00110.183920.0006
Override
Cache load0.00220.3552350.0001
Sytem overhead
Fetch class attribute can translate value0.00100.171430.0003
Fetch class attribute name0.00160.257190.0002
XML
Image XML parsing0.00150.254630.0005
class_abstraction
Instantiating content class attribute0.00000.0036120.0000
General
dbfile0.00120.1909300.0000
String conversion0.00000.001640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 26
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs