Date attribute within composer
Permalink
Hi - I'm using a date attribute within composer, but I'm having troubles having it display on the actual page. I have it displaying properly in the blog page list with this:
But that doesn't work when I place it in an html block within composer.
Any ideas?
Thanks
Kurtopsy
But that doesn't work when I place it in an html block within composer.
Any ideas?
Thanks
Kurtopsy
Thanks hutman. I am using 5.6 and I tried to use the php block and to no avail. Must not be able to call page attributes in composer.
I think the issue is that you can't call Page Attributes from blocks, not really anything to do with Composer.
One cheat that I have done before is to create a Custom Template for the Content/HTML block that has the desired code in it, and then add a blank block of that type with the Custom Template to your page where you want the attribute to display. If you do that you will need to put this at the top of your Custom Template code
One cheat that I have done before is to create a Custom Template for the Content/HTML block that has the desired code in it, and then add a blank block of that type with the Custom Template to your page where you want the attribute to display. If you do that you will need to put this at the top of your Custom Template code
$c = Page::getCurrentPage();
Good idea! It sort of worked. It's displaying a date, but not the date in my attribute. Using the same php as above, but replaced $page with $c; outputted December 31, 1969.
Can you provide the code that you have in your Custom Template?
<?php defined('C5_EXECUTE') or die("Access Denied."); $c = Page::getCurrentPage(); ?> <div id="HTMLBlock<?php echo intval($bID)?>" class="HTMLBlock"> <?php echo $content; ?> <span> <i class="fa fa-calendar"></i> <?php $date = $c->getAttribute('date_time'); echo date('F j, Y', strtotime($date)); ?> </span> </div>
And you have this block added to the page which has the attribute with handle 'date_time' set, correct?
Correct.
I guess I'm not sure, this should work. You will just need to put some echo or var_dump statements in there to see what your variables are returning and see where the disconnect is I think.
Sounds good. Thanks so much for all your help.
2) If you are trying to get the attribute value of the current page you need to use $c not $page