Call custom date field in pagelist block
PermalinkI 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'); ?>
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') ?>
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.
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' ); }
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 ??
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...
Thankyou