Display the content of the node

Author Message

Leonardo López

Wednesday 22 June 2005 6:24:06 am

Hello... A doubt...
I put this code:

{* Fetch node number 42. *}
{let node=fetch( 'content', 'node', hash( 'node_id', 42 ) )}

{* Display the name of the node. *}
{$node.name}

{/let}

But alone this shows me the name of the node... Since I can do in order that it shows the entire content of the node?

Kristian Hole

Wednesday 22 June 2005 11:02:42 am

Take a look at node_view_gui in the docs :)

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Leonardo López

Tuesday 28 June 2005 6:35:34 am

Thanks a lot Kristian...

I use this:
{let myvar=fetch(content,node,hash(node_id,115))}
{node_view_gui view=full content_node=$myvar}
{/let}
And works good... It shows the full view of the node but how can i do if i wan to display only the question of the pool (the node is a pool) or the options???

with {$node_name} display the name of the node.. good....but now i put some like this to show only the question of the pool:

{let myvar=fetch(content,node,hash(node_id,115))}
{attribute_view_gui attribute=$node.object.data_map.question content_node=$myvar}
{/let}

But is not work.... do you know how can i do to show for separate the parts of the pool (name, question, options) ???....... help me friend... thanks

Daniel Beyer

Tuesday 28 June 2005 9:08:43 am

Hi,

I think you did a simple mistake. Try this:

{let myvar=fetch(content,node,hash(node_id,115))}
{attribute_view_gui attribute=$myvar.object.data_map.question}
{/let}

(assuming the identifier of the used class attribute is "question")

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Leonardo López

Tuesday 28 June 2005 11:27:55 am

Hi Daniel, That sentence shows the question + the options, but i believe that is not way to shows the options and the question for separate...... thanks a lot friend.

Daniel Beyer

Tuesday 28 June 2005 1:56:42 pm

Hi Leonardo,

I misunderstood your post. I thought you were talking about displaying attributes in general. Actually you were talking about the poll-class that comes with eZ publish.

In this case take a look into template /design/standard/templates/content/datatype/view/ezoption.tpl.
In line 2 you will see that you can display the question (the name provided by datatype "ezoption") with this:

{$attribute.content.name|wash( xhtml )}

Note that you give the template the variable $attribute which is in your case "$myvar.object.data_map.question".

Because of this you will get the question with this:

{let myvar=fetch(content,node,hash(node_id,115))}
{$myvar.object.data_map.question.content.name|wash( xhtml )}
{/let}

You can do the same with the answers, too. It's almost the same...Just take a look at the template of datatype ezoption (line 5 - 11).
And you can do this for the other attributes, too. In this case you have to check of which datatype the attribute is and look into the appropriate template (or just switch on the template debug to find out which templates are used).

Hope this time my reply was applicable to your post ;)

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Leonardo López

Wednesday 29 June 2005 6:07:58 am

thank you men... :)

Leonardo López

Wednesday 29 June 2005 6:47:06 am

Daniel, how can i do to show the pool whitout have to put the node_id in the sentence? i want to shows the pool that i make in the administration site without have to change again the node_id in the code...

i hope you understand my question... sorry but my english is not too well...

Daniel Beyer

Wednesday 29 June 2005 8:15:35 pm

Hi Leonardo,

I hope I get you right. It's pretty early in the morning and my coffee didn't done its job yet.

Instead of using a fix id in your template you could use a variable, too. Your code than would look like that.

{default pollNodeID = 115}

(...some other code ...)

{let myvar=fetch(content,node,hash(node_id,$pollNodeID))}
{attribute_view_gui attribute=$myvar.object.data_map.question}
{/let}
{/default}

Actually this isn't pretty much the same as you've got before. But instead of {default pollNodeID = 115} you could do some other things, too:

Get the NodeID from a ini-file named polls.ini:

{default pollNodeID = ezini( 'Polls', 'CurrentPollNodeID', 'polls.ini' )}

Get the NodeID what is specified in the address (e.g. /content/view/full/2/poll_id/117):

{default pollNodeID = $view_parameters.poll_id}

Get the NodeID depending on the current node we're watching (e.g. by visiting node /content/view/full/117):

{default pollNodeID = $node.node_id}

The same like last one, but you include this code outside of $modules_result.content (e.g directly in pagelayout.tpl):

{default pollNodeID = $module_result.node_id}

Get the NodeID of the last poll that was published (and this one is probably the answer to your question):

{default pollNodeID = fetch('content','tree',hash(parent_node_id,2,
                                   sort_by,array(published,true()),
                                   class_filter_type,include,
                                   class_filter_array,array(27),
                                   limit,1)).0.node_id}


------
or even better:
------

{let myvar=fetch('content','tree',hash(parent_node_id,2,
                                   sort_by,array(published,true()),
                                   class_filter_type,include,
                                   class_filter_array,array(27),
                                   limit,1)).0}
{$myvar.object.data_map.question.content.name|wash( xhtml )}
{/let}


I hope the examples are working - if not: blame the coffee and not me ;)

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Leonardo López

Thursday 30 June 2005 6:23:01 am

Good Morning Daniel, i hope that you have enjoyed your cofee...

The code that gave me to fetch the poll ID did not work very well... Because it was showing another thing that was not the poll, it shows some like "Default object view"... I cant fetch the node ID yet :(

Im trying to find the file polls.ini but i cant... where it is?...... I estimate indeed the time that you dedicate to answering my questions... thanks a lot!

Daniel Beyer

Thursday 30 June 2005 7:55:37 am

Hi Leonardo,

the file poll.ini does not exists. If you want to use this, you need to create it first. The content of it would look like this:

[Polls]
CurrentPollNodeID=115

But you probably don't want to use this solution, as you still have to set the id by hand after publishing a new poll.

As the examples work for me, I suggest you post the complete code of your template and tell me where and when it is included in your templates.

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Leonardo López

Thursday 07 July 2005 8:50:08 am

Hello Daniel... How's everything... I hope that well...

With regard to display the polls, still I have to put the ID of the node by hand in the code... I wish to appear the last poll published in the administrator interface without having to place the node ID in the code... For the present i leave it that way... later i will fix it...

Other question my friend, I am trying to personalize the site. when a user logged in, his name most be displayed in some part of the page, fot that i use this code:

{let usuario=fetch('user','current_user')}
{$usuario.contentobject.name}
{/let}

But i have a problem, when other user logged in, There continues going out the name of the previous user, As if there was remaining guarded in the cache of the system the variable of the previous user... Also i like to know since how I can place a button in order that the user is disconnected or closes the meeting...

greetings my friend... and excuse my bad english...

Daniel Beyer

Thursday 07 July 2005 3:19:25 pm

Hi Leonardo,

back to the problem with the last published poll...

Assuming you place your polls like this:

- Content-Root - NodeID: 2
-- Polls - NodeID: 100
--- Like my page? - NodeID: 110
--- How old are you? - NodeID: 120
--- ...

In this case you can get the last published poll with this code:

{default PollPlaceID=100
         PollClassIDs=array(27)
         currentPoll=fetch('content','tree',hash(parent_node_id,$PollPlaceID,
                                   sort_by,array(published,true()),
                                   class_filter_type,include,
                                   class_filter_array,$PollClassIDs,
                                   limit,1)).0}

Current poll's name is: 
{$currentPoll.object.name|wash( xhtml )}
{/default}

Where:
PollPlaceID: Has to be somewhere obove the place where all your polls are stored (in my example 2 or 100)
PollClassIDs: An array of classes you use for your polls. The default poll-class that comes with eZ publish should have the ID 27. If you created other poll-classes, just add them like this: array(27,50,99,500)

----------------------------------

According to the user-name-problem:
The code you provided is correct for that purpose. The problem you described may occur, if you use that code in override-templates. I discovered similar problems with override templates and wrong variables in the past (with eZ publish < v3.4.0). Maybe it helps if you do not make use of a {let}:

{fetch('user','current_user').contentobject.name}

---------------------

I think in your last question you ask how to give a user the possibility to logout. You can do this either with a simple link or with a button.

Link:

<a href={"/user/logout"|ezurl}>{'Logout'|i18n( 'design/standard/toolbar' )}</a>

Button:

<form name="logout" method="post" action={"/user/logout"|ezurl}>
<input name="LogoutButton" type="submit" value="{'Logout'|i18n( 'design/standard/toolbar' )}">
</form>

As you can see: The best way to logout a user is to redirect him to "index.php/user/logout".

-----------------

Don't worry about your english - actually mine isn't perfect, too.

Greetings, Daniel.

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Leonardo López

Friday 08 July 2005 5:16:30 am

Thanks a lot Daniel !!!

Leonardo López

Friday 08 July 2005 7:09:32 am

About the button to log out the users its works perfect really thanks a lot my friend! I'm learning enough things thanks to you...

the module of the polls still have a problem, i was studying the code that you gave me and i understand good it... but it shows the first poll publicated in the Polls Folder (the name of the poll is "Pi" ezpublish takes it as default) i dont know what its happen... i modified the order to sort the polls in the admin interface but it still shows the "Pi" poll...

Daniel Beyer

Friday 08 July 2005 7:26:29 am

Hi Leonardo,

the sort thing was my fault. It's really the wrong order. Just change your code to that:

{default PollPlaceID=100
         PollClassIDs=array(27)
         currentPoll=fetch('content','tree',hash(parent_node_id,$PollPlaceID,
                                   sort_by,array(published,false()),
                                   class_filter_type,include,
                                   class_filter_array,$PollClassIDs,
                                   limit,1)).0}

Current poll's name is: 
{$currentPoll.object.name|wash( xhtml )}
{/default}

It was that line, which was wrong:

Change from:
sort_by,array(published,true()),

Change to:
sort_by,array(published,false()),

Hope this works...

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Leonardo López

Friday 08 July 2005 11:07:04 am

Very well my friend! now the module works perfectly! thanks again...!

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