Include PHP code in TinyMCE to add Date to Footer Block

Permalink 1 user found helpful
I want to include the current date in my Footer block. If I include
<?php echo date("F j, Y, g:i a"); ?>
in TinyMCE it gets stripped out. From reading the TinyMCE documentation it appears as though you can't include any server side code in its editor.

So is there any way of doing this in my Footer content block or do I need to put the footer content directly into my template xxx.php file?

I've read about attributes and wonder whether that provide the solution!

My preference is to do it in a content block so the footer is editable inside C5.

Thanks,
Nevillehttp://www.surfulater.com

nevf
 
nevf replied on at Permalink Reply
nevf
To reply to my own post I haven't worked out how to do this in PHP, but I have in Javascript.

In TinyMCE click on the [HTML] toolbar button and paste the following in where you want the current year displayed.

<script type="text/javascript">// <![CDATA[
var da = new Date();
document.write(da.getYear());
// ]]></script>

Of course this will let you embed any Javascript code using TinyMCE.

Neville
TheRealSean replied on at Permalink Reply
TheRealSean
I have just modified my view for the content View to allow the date to be added, I used to use {YEAR} and use a string replace.

Now I have added the following in my content block to allow me to add a {format} which I pass through to the date function.

$content = preg_replace('/{([a-zA-Z\s]{0,10})}/e', "date('$1')", $controller->getContent());
print $content;

Then within the content I add {Y}.
jordanlev replied on at Permalink Reply
jordanlev
I have been thinking about this problem a lot recently. I usually only need the formatted date to appear in the site footer, so I usually just leave it hardcoded into my template instead of making it a content block. But some clients need to change it more frequently than I'd imagine.
I think I would actually create a custom template for the content block that did this conversion in the view.php file instead so as not to accidentally mess up "real" content somehow.
(But your solution is excellent as well -- just thinking out loud here).
JohntheFish replied on at Permalink Reply
JohntheFish
If it is the last updated date for the page you want, you could try my block 'last Updated'
http://www.concrete5.org/marketplace/addons/last-updated/...