Forums / Developer / Current page node id [SOLVED]

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