Forum Moderators: coopster
I hope you know what I'm trying to say here, for Smarty users this looks simple, I imagine.
What I would like to know is if there is an easier way to insert areas such as banners, user comment areas, timestamps etc in areas of my template. I could simply create lots of smarty_insert_funcName(), but that is so repetitive, I wish there was an easier way, such as:
{uncacheable_area}
This area should never be cached!
{/uncacheable_area}
Is there a way to have such a feature? Is it already built into Smarty, and I am just not aware of it? And if not, is there anything I can do to create that feature myself without having to completely abandom Smarty, which fortunately has helped me separate application logic from presentation?
Best regards,
SOLUTION
Add the following function on the top of your application, before any HTML output. Usually this is inside some file with all database connection calls and function calls:
function smarty_block_dynamic($param, $content, &$smarty) {
return $content;}
$smarty->register_block('dynamic', 'smarty_block_dynamic', false);
And here is your template file:
{dynamic}Now is: {'0'¦date_format:'%D %H:%M:%S'}
... do other stuff ...
{/dynamic}
Now anything in between the dynamic tag will not be cached. The entire template will be cached, but that specific area inside the dynamic tag will be recompiled on each call of the template.
I found this solution here, on the Smarty Documentation website [smarty.net].
I'm happy to have found a solution, and quite surprised at how simple it is. This will make development with templates a lot easier. Hope this helps someone. =)