Current page node id [SOLVED]

Author Message

Lo' F.

Monday 27 September 2010 9:56:43 am

Hello again,

Having a little trouble getting the current page node id from a content/view/line.tpl, where I need to compare the line embedded object node id to the current page node id.

Any suggestion would be highly appreciated.. meanwhile I'll keep tryng..

loredanaebook.it

Lo' F.

Monday 27 September 2010 11:44:22 am

Let's say I created 4 frontpages under the root node.

In the right column of these frontpage objects I embedded, on a line view, each of them as links to the others. The thing is I need to deactivate the link of the one is already the displayed page. In order to accomplish this, I need to compare each {$object.main_node.node_id} to the current one.

This {$object.main_parent_node_id} returns, of course, the root under which I created those nodes, and so far it's the only outcome I have been able to get.

I need to create the conditional statement and so utilize the current page node_id in the content/view/line.tpl which is the template through which those links come from.

... hope somebody can help..

loredanaebook.it

Håvard Bergersen

Monday 27 September 2010 12:48:31 pm

If you have one template for all the subpages, you could do something like this:

To create right column in subpage template:

{def $pages=fetch( 'content', 'list', hash( 'parent_node_id', 'something' ) )}

{foreach $pages as $p}
   {node_view_gui content_node=$p view=line current_node_id=$node.node_id}
{/foreach}

The lineview template

{if eq( $current_node_id, $node.node_id )}
{$node.name|wash()}
{else}
<a href={$node.url|ezurl}>{$node.name|wash()}</a>
{/if}

This should work, but there may be a cache issue.

Lo' F.

Monday 27 September 2010 1:36:16 pm

Thank Håvard for your reply.

I actually embedded those frontpage objects of the frontpage class from the admin back-end.

And making the adjustments from the contentview/line.tpl template..

{default node_name=$object.main_node.name node_url=$object.main_node.url_alias}
<h2>{if $node_url}<a href={$node_url|ezurl}>{/if}{$node_name|wash}{if $node_url}</a>{/if}</h2>
{/default}

Here the $current_node_id doesn't work..

So far... among with all the attempts aimed to get the current page url (..unable to get the node_id from here I was trying to get the current page url)...:

- {ezpagedata().path|ezurl} or {$module_result.path|ezurl} return a too short result ( "/index.php/ita" )

- {$child.url|ezurl()} too long ( "/index.php/ita/the-page-I-need/its-last-child/its-last-child's-last-child" )

loredanaebook.it

Håvard Bergersen

Monday 27 September 2010 1:44:14 pm

Ahhh... Okey....

Well,,could you use {$module_result.node_id} ? Or {$module_result.path_array}

{if $module_result.path_array|contains( $node.node_id )} ?

Or am I not understanding anything now hehe... :)

Lo' F.

Monday 27 September 2010 2:12:25 pm

.. you have almost sorted my problem out..!

At least I am starting getting something that is probably far from what I should do but kind of.. working after all...

See how it comes:

{if $child.url|ezurl|contains($object.main_node.url)}
{$node_name|wash}


{else}
<a href="{$node_url|ezurl}">{$node_name|wash}</a>
{/if}

..it could be a cover for the time being...

but if I could get a proper current page node_id either its url should be better..

loredanaebook.it

Håvard Bergersen

Monday 27 September 2010 2:19:36 pm

{if $node.path_array|contains( $object.main_node.node_id ) }

Maybe a little cleaner :)

You can't reach the current node id outside the pagelayout.tpl...

Lo' F.

Monday 27 September 2010 2:28:33 pm

"
{if $node.path_array|contains( $object.main_node.node_id ) }

Maybe a little cleaner :)

You can't reach the current node id outside the pagelayout.tpl...

"

{$node.path_array|ezurl} returns "/index.php/ita"

loredanaebook.it

Håvard Bergersen

Monday 27 September 2010 2:31:17 pm

{$node.path_array} returns an array of node id's.. So you can't use the |ezurl operator on it :)

Lo' F.

Monday 27 September 2010 2:39:06 pm

"

{$node.path_array} returns an array of node id's.. So you can't use the |ezurl operator on it :)

"

..okey..

but yet it didn't return nothing when I tried it in the {if} condition...

loredanaebook.it

Håvard Bergersen

Monday 27 September 2010 2:43:28 pm

Hm.... Just tested it and it works here.. Tried dumping all the variables to inspect it?

{$node.path_array|attribute(show)}
{$object.main_node|attribute(show)}

Well,, good luck & good night :)

Lo' F.

Monday 27 September 2010 3:22:45 pm

..nope...

Only {$object.main.node|attribute{show}} works from here (..content/view/line.tpl) while {$node.path_array|attribute(show)} returns an empty Attribute Type Value.

... We'll see tomorrow. Good night!

loredanaebook.it

Nathan Kelly

Monday 27 September 2010 11:09:56 pm

If {$object.main_node|attribute(show)} is working you should be able to get the path_array with

{$object.main_node.path_array|attribute(show)}

(keep in mind however if your node is placed in more than one location this will only find the main_node path_arry which will be different to any of the co-located nodes.)

Pardon me while I burst into flames...

Bayron Guevara

Monday 27 September 2010 11:59:23 pm

I think you are trying to call a global variable inside a content view, from here you need to use the # character to indicate access to the global scope. So maybe the following code solve your problem:

{if eq($#module_result.node_id, $object.main_node_id)}
  {$node_name|wash}
{else}
  <a href="{$node_url|ezurl}">{$node_name|wash}</a>
{/if}

Web Developer & Modern Philosopher
Visit http://www.laprensa.hn, http://www.diez.hn, http://www.estilo.hn

Lo' F.

Tuesday 28 September 2010 4:02:49 am

"

I think you are trying to call a global variable inside a content view, from here you need to use the # character to indicate access to the global scope. So maybe the following code solve your problem:

{if eq($#module_result.node_id, $object.main_node_id)}
  {$node_name|wash}
{else}
  <a href="{$node_url|ezurl}">{$node_name|wash}</a>
{/if}
"

Thank you guys, but this doesn't work too..

I thought that could have worked because in theory that's what I am trying to do...

The only way I can get the current object page from the content view seems to be through its $child,

{if $child.path_array|contains($object.main_node.node_id)}ok{/if}

even though this is not the answer 'cause if there are not children in there it has no sense at all..

loredanaebook.it

Kévin S.

Thursday 30 September 2010 9:33:25 am

Hi Lo'F !

I had a similar problem recently. I solved it using ezhttp operator and a HTML GET parameter, which was the id of the node to display.

You can find more information in this topic.

Hope it'll help !

___

Kévin

Lo' F.

Saturday 09 October 2010 7:47:28 am

"

I had a similar problem recently. I solved it using ezhttp operator and a HTML GET parameter, which was the id of the node to display.

"

Hi Kévin! Thanks to your hint I finally got the perfect solution!

Your ezhttp took me here http://doc.ez.no/.../Template-operators/Data-and-information-extraction where I came across this module_params

Made it run this way ..

module_params()|attribute(show)

I got this outcome...

"
Attribute Type Value
module_name string 'content'
function_name string 'view'
parameters array Array(2)
>ViewMode string 'full'
>NodeID string 276
"

and...

{module_params()[parameters][NodeID]}

gave me the node id I was looking for, so I eventually made it work!

{if module_params()[parameters][NodeID]|eq($object.main_node.node_id)}...

Thank you again!

loredanaebook.it

Kévin S.

Tuesday 12 October 2010 5:20:23 am

Oh, nice ! Didn't find this one, very useful (I knew ezpublish could not let us without the current node ID !)

Thank you for telling how you solved this problem !

___

Kévin

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 10:20:05
Script start
Timing: Jan 18 2025 10:20:05
Module start 'layout'
Timing: Jan 18 2025 10:20:05
Module start 'content'
Warning: PHP: E_DEPRECATED Jan 18 2025 10:20:06
trim(): Passing null to parameter #1 ($string) of type string is deprecated in /home/ze/public_html/share.se7enx.com/var/community/cache/template/compiled/table-02cf899a6d707917c58210ed54ffe2ff.php on line 147
Timing: Jan 18 2025 10:20:06
Module end 'content'
Timing: Jan 18 2025 10:20:06
Script end

Main resources:

Total runtime1.2507 sec
Peak memory usage4,096.0000 KB
Database Queries126

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 589.0469152.6250
Module start 'layout' 0.00700.0034 741.671939.4531
Module start 'content' 0.01041.2384 781.1250892.1406
Module end 'content' 1.24880.0019 1,673.265640.3750
Script end 1.2507  1,713.6406 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.2748160.0002
Check MTime0.00150.1216160.0001
Mysql Total
Database connection0.00130.106110.0013
Mysqli_queries1.073585.82801260.0085
Looping result0.00170.13581240.0000
Template Total1.219997.520.6100
Template load0.00240.194320.0012
Template processing1.217597.340120.6087
Template load and register function0.00010.007910.0001
states
state_id_array0.00100.077810.0010
state_identifier_array0.00130.102220.0006
Override
Cache load0.00250.19861690.0000
Sytem overhead
Fetch class attribute can translate value0.00070.052350.0001
Fetch class attribute name0.00190.1517220.0001
XML
Image XML parsing0.00440.352750.0009
class_abstraction
Instantiating content class attribute0.00010.0071340.0000
General
dbfile0.00320.2574350.0001
String conversion0.00000.000740.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
16content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
18content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
42content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
11content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
5content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
14content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
5content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
2content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1content/datatype/view/ezxmltags/th.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/th.tplEdit templateOverride template
6content/datatype/view/ezxmltags/tr.tpl<No override>extension/community/design/community/templates/content/datatype/view/ezxmltags/tr.tplEdit templateOverride template
5content/datatype/view/ezxmltags/td.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/td.tplEdit templateOverride template
1content/datatype/view/ezxmltags/table.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/table.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 128
 Number of unique templates used: 14

Time used to render debug report: 0.0002 secs