eZ Community » Forums » Developer » Current page node id [SOLVED]
expandshrink

Current page node id [SOLVED]

Current page node id [SOLVED]

Monday 27 September 2010 6:56:43 pm - 17 replies

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..

Modified on Saturday 09 October 2010 4:48:53 pm by Lo' F.

Monday 27 September 2010 8:44:22 pm

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..

Modified on Monday 27 September 2010 8:45:55 pm by Lo' F.

Monday 27 September 2010 9: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.

Modified on Monday 27 September 2010 10:18:12 pm by Håvard Bergersen

Monday 27 September 2010 10: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" )

Modified on Monday 27 September 2010 10:38:31 pm by Lo' F.

Monday 27 September 2010 10: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... happy.gif Emoticon

Modified on Monday 27 September 2010 11:00:51 pm by Håvard Bergersen

Monday 27 September 2010 11: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..

Modified on Monday 27 September 2010 11:13:33 pm by Lo' F.

Monday 27 September 2010 11:19:36 pm

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

Maybe a little cleaner happy.gif Emoticon

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

Modified on Monday 27 September 2010 11:25:18 pm by Håvard Bergersen

Monday 27 September 2010 11:28:33 pm

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

Maybe a little cleaner happy.gif Emoticon

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

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

Monday 27 September 2010 11:31:17 pm

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

Monday 27 September 2010 11:39:06 pm

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

..okey..

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

Monday 27 September 2010 11: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 happy.gif Emoticon

Modified on Monday 27 September 2010 11:52:58 pm by Håvard Bergersen

Tuesday 28 September 2010 12:22:45 am

..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!

Tuesday 28 September 2010 8:09:56 am

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.)

Tuesday 28 September 2010 8:59:23 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}

Tuesday 28 September 2010 1:02:49 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}

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..

Thursday 30 September 2010 6:33:25 pm

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

Saturday 09 October 2010 4:47:28 pm

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!

Tuesday 12 October 2010 2:20:23 pm

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

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from