Call custom date field in pagelist block

Permalink
Hi There

I am trying to make a custom pagelist for a blog style layout. It calls my page attributes for thumbnail and I need get a custom date field and insert it.

I can do this on a normal page with

<?php $date = Loader::helper("date");
echo $date->getSystemDateTime($c->getCollectionAttributeValue('tourdate'), $mask = 'D F j G:i') ?>


but I need to call this in my page list custom block and cannot work out the relevant php? Can you help please?

I have the below in my view.php block

<?php
   defined('C5_EXECUTE') or die("Access Denied.");
   $textHelper = Loader::helper("text");
   $imgHelper = Loader::Helper('image');
   $date = Loader::helper("date");
   // now that we're in the specialized content file for this block type,
   // we'll include this block type's class, and pass the block to it, and get
   // the content
   if (count($cArray) > 0) { ?>
   <?php
   for ($i = 0; $i < count($cArray); $i++ ) {
      $cobj = $cArray[$i];
      $target = $cobj->getAttribute('nav_target');
      $title = $cobj->getCollectionName();
      $date = $cobj->getCollectionDatePublic('M j, Y'); ?>

View Replies:
burbleweb replied on at Permalink Reply
Hi There - sorry just hoping to get an answer so bumping this. Any ideas Gurus?

Thankyou
goldhat replied on at Permalink Reply
This is a bit confusing because you don't share what happens when you try the same code you give as an example for a "normal page". Why not just use that only with getAttribute instead of getCollectionAttributeValue are you not getting anything returned from $cobj->getAttribute('tour_date') ?

Presuming that code works on a regular page why would this not work?

echo $date->getSystemDateTime($c->getAttribute('tourdate'), $mask = 'D F j G:i') ?>
burbleweb replied on at Permalink Reply
Sorry - I see I'll put that below. to be clear I actually have bugger all understanding of php I just try and cobble together what I find to make small tweaks and follow forum posts and guides to help so I may be missing something blindingly obvious.

If I insert the code

<?php if ($cobj->getAttribute('tourdate')) {} ?>


In my page list block, nothing gets printed on output at all. No errors, but nothing where it should be. I have double checked my attribute and it has definitely got the handle "tourdate" and is a Date / Time attribute asking users for both the date and time.

If I input the code you suggested:

<?php echo $date->getSystemDateTime($c->getAttribute('tourdate'), $mask = 'D F j G:i') ?>


I get the following error:

Fatal error: Call to a member function getSystemDateTime() on a non-object in /blocks/page_list/templates/burble_index_thumbnail/view.php on line 38


at the first point in the page where that would come (line 38 is the line the new code of yours sits on). Do I need to put something else in the page loaders etc?

Hope that is clearer. Thanks for your help, much appreciated.
goldhat replied on at Permalink Reply
You have to use either echo or print to actually output something. So in the line below there is no output because we are just checking "IF" something is true, and then we are doing nothing!

if ($cobj->getAttribute('tourdate')) {
  // output can go here
  // left blank this outputs nothing
}


First you need to make sure $cobj->getAttribute('tourdate') has a value so try this test below:

if ($cobj->getAttribute('tourdate')) {
  print "TESTING TOUR DATE: ".$cobj->getAttribute('tourdate');
}


Now if you saw output of the raw tourdate attribute you can proceed to try this. Same example I gave you earlier but in this situation $cobj is the collection object, not $c.

echo $date->getSystemDateTime( $cobj->getAttribute('tourdate'), $mask = 'D F j G:i' );


Now if that worked tie it together by wrapping that line inside the if statement in case the attribute is sometimes not available:

if ($cobj->getAttribute('tourdate')) {
 echo $date->getSystemDateTime( $cobj->getAttribute('tourdate'), $mask = 'D F j G:i' );
}
burbleweb replied on at Permalink Reply
Thanks for that.

I have tried this and

<?php
if ($cobj->getAttribute('tourdate')) {
  print "TESTING TOUR DATE: ".$cobj->getAttribute('tourdate');
}
?>


Works great, although as you suggest the output needs revising to be a different format - the next stage however does not and I get the warning.

Fatal error: Call to a member function getSystemDateTime() on a non-object in blocks/page_list/templates/burble_index_thumbnail/view.php on line 38


So is there something incorrect with:

echo $date->getSystemDateTime ??
burbleweb replied on at Permalink Reply
Hi There - Just bumping this up in hope of help - I can echo my date attribute fine, but I cannot work out how to apply the date mask to rejig? I have looked and tried but hitting a wall.

Any ideas? Basically I just want to be able to use the php date/time system to tweka the output of my date custom attribute which is currently - 2014-02-13 15:00:00

The help above worked to call the date - which I should have known - by the apllying the mask doesn't. Penny for your thoughts?

Thanks

http://www.concrete5.org/api/Concrete5_Helper_Date.html...