Display article create date

Author Message

Steven Stieng

Friday 28 May 2010 8:35:34 am

I'm not able to display article create date.
My class consist of the following attributes:

  • Name
  • Intro
  • body
  • image 

 I'm fetching the articles using the following code:

{def $complaints=fetch('content', 'list', hash('parent_node_id', 75, 'limit', 5))}
<ul>
    {foreach $complaints as $complaint}
      <li>
        <a href={$complaint.path_identification_string|ezurl}>{$complaint.name|wash}</a> [{$complaint.data_map.published|l10n(date)}]
      </li>  
    {/foreach}  
</ul>

I'm able to list the names, but not the dates.

I've tried different variations:
{$complaint.data_map.published}
{$complaint.data_map.date_attribute_id.content.timestamp|l10n(date)}
{attribute_view_gui attribute=$complaint.data_map.date_attribute_id}
{$complaint.data_map.publication_date.content.timestamp|l10n(shortdatetime)}
What am I missing?

Gaetano Giunta

Friday 28 May 2010 10:39:25 am

You are missing the fact that the publication date is not an attribute of the object ;-)

In short: every content object, as available in the templates, is made up of:

  1. its attributes, as defined in the content class
  2. some extra metadata

For 1, you access them using $obj.data_map, and you can use them with attribute_view_gui

For 2, you access them directly: $obj.published, $obj.name etc...

Your best friend is the online doc: look at http://ez.no/doc/ez_publish/technical_manual/4_x/reference/objects/ezcontentobject - for every member of $obj listed the datatype is clearly indicated

(note: the manual page is not very clear in that it uses the term "attribute" to denote two different things; we have the same problem for newcomers trying to distinguish a 'content object' from a 'template object')

Principal Consultant International Business
Member of the Community Project Board

Håvard Bergersen

Friday 28 May 2010 11:13:50 pm

And just in case you don't know:

{$complaint|attribute(show)} Will tell you a lot.. :)

Steven Stieng

Wednesday 02 June 2010 12:37:13 am

Thanks for the reply guys. But none of you made any sense really :)
(sorry, I'm noob )

I am assuming the folloing:

1. Articles (also knows as objects) has some system attributes. One being the creation date.

2. I do not need to create a date attribute for the class, since this is recorded automatically (one should never have to manually enter creation date of an article)

If you look at my example above, you will see that I am using 'attribute_view_gui' and 'data_map'.
I'm also using Håvards suggestions to output information about whatever object I have in my $complaint variable using

{$article|attribute(show, 1)}
{$article.data_map|attribute(show, 1)}

Can anyone give me an example of the code I need to use?

Steven E. Bailey

Wednesday 02 June 2010 2:56:15 am

try {$complaint.object.published|datetime}

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

Steven Stieng

Wednesday 02 June 2010 3:13:00 am

Oh, great! Thanks! Also using {$complaint.object|attribute(show, 1)} shows be all the attributes of the object. 

Now, can you tell me why the publish date is formatted like this?

1275052797, 1275052846, 1275052903

They don't really look like dates to me :) 

Steven E. Bailey

Wednesday 02 June 2010 4:03:42 am

Unix time. That's what the datetime operator was for in the above example.

http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_operators/formatting_and_internationalization/datetime

try {$complaint.object.published|datetime( 'custom', '%h:%i %a %d %F %Y' )}

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

Steven Stieng

Wednesday 02 June 2010 4:14:15 am

Aha!
I've never seen UNIX time before (as I can recall)
Thank you very much! 

Sujit Sth

Tuesday 04 January 2011 8:23:03 pm

Hi,

For published date of an article:

{$node.object.published|l10n(date)}

for all other date format click link below:

http://blog.developeronhire.com/tag/published-date/

Thank you

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