Hi
I’m new to MODx, using 2.0.1 and character encoding UTF-8. I’m trying to format a date in a Template. It is the pub_date of the current resource. I have this line of code:
<p class="dt"><?php strftime("%A, %d %M %Y", $modx->documentObject[$pub_date]) ?></p>
It returns (with the correct CSS styling!):
documentObject[$pub_date]) ?>
I have tried a lot of variations on the code with no success. Have also tried using the snippet FormatDate - it returns a completely wrong date. Can someone please spot where I’m going wrong?
Thanks.
OK, I’ve got FormatDate to work by calling it uncached. Thanks to an earlier thread which I’ve just found for suggesting that.
However, would still really appreciate any thoughts on why the code I quoted above does not work. Am I trying to do the right thing but in the wrong place? Or am I making another newbie mistake through not really understanding what I’m doing? <g>
Quote from: yorkie at Nov 14, 2009, 07:01 PM
OK, I’ve got FormatDate to work by calling it uncached. Thanks to an earlier thread which I’ve just found for suggesting that.
However, would still really appreciate any thoughts on why the code I quoted above does not work. Am I trying to do the right thing but in the wrong place? Or am I making another newbie mistake through not really understanding what I’m doing? <g>
It doesn’t work because you can’t have PHP code embedded in HTML in MODx. You’d have to move that code to a snippet and put a snippet tag in the template (or wherever you want the date to appear):
Tag: [!MyDateSnippet!]
MyDateSnippet contents:
<?php
return strftime("%A, %d %M %Y", $modx->documentObject[$pub_date]);
?>