Date Custom Attribute

Permalink 2 users found helpful
Hello!

I have spent the evening trying to find this, so I am hoping someone will help :)

I am currently building a custom template, and I need to display a date based custom attribute.

Does anyone know how I'd do this?

One post I found, suggested using the following code, but this is returning nothing on my page.

<?php
if ($c->getAttribute('CUSTOM ATTRIBUTE VALUE')) {
echo strftime("%d-%m-%Y",strtotime($c->getAttribute('CUSTOM ATTRIBUTE VALUE')));
?>


Any help would be greatly appreciated :) I'm using the the latest version of C5

Thanks

Paul

 
dbeer replied on at Permalink Reply
dbeer
Hi Paul,

It sounds like the attribute value has not been set in the context of the page (collection) in which the code is executing. If you are not getting an error, just nothing displayed, that is the most likely.

Try setting the value of one of the custom attributes associated with a page by default, such as meta_title, and then use your code to display the value. If you get the value displayed, then you will need to verify the value of your custom object is getting set within the context of the specific page in question.

Regards,

Don
GeckoSocial replied on at Permalink Reply
Hi Don,

Many thanks for your reply - I feel dumb!

I was using the wrong custom attribute, and there was a slight error in my code, correct code should be:

<?php
            if ($c->getAttribute('expiry_date')) {
            echo strftime("%d-%m-%Y",strtotime($c->getAttribute('expiry_date')));
            } ?>


Many thanks for your help, I would have gone round in circles had you not pointed me in the right direction :-)

Paul