|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bg17aw Smarty n00b
Joined: 14 Nov 2016 Posts: 3
|
Posted: Wed Nov 16, 2016 7:28 pm Post subject: how to replace "echo filemtime('filename.css')" wi |
|
|
In the header of my template, I add a random string to force load of css and Javascript files:
Code: |
<link rel="stylesheet" href="/default.css?<?php echo filemtime('/default.css') ?>" type="text/css" >
<script src="js/main.js?<?php echo filemtime('js/main.js') ?>"></script> |
However, no idea how to achieve the same thing in Smarty.
Any help to achieve THE EXACT same thing?
I found a solution about declaring a smarty variable with a random value, but the above code is a more elegant solution, so I would like to keep it.
Thanks! |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Nov 16, 2016 9:23 pm Post subject: |
|
|
That's hardly a random value, and you, indeed, can do the same in Smarty.
Optimal would be to write a custom modifier that would compose an entire link. Something like Code: | function smarty_modifier_???($source, $rel = "stylesheet", $type = "text/css")
{
return sprintf("<link rel=\"%s\" href=\"%s?%u\" type=\"%s\"/>\n", $rel, $source, filemtime("{$_SERVER['DOCUMENT_ROOT']}/$source"), $type);
} |
Then Code: | {"/default.css"|smarty_modifier_???} |
Do make sure that the results of your transform are cached within template. Else you'd waste FS calls on polling mtime for each file each time your template is rendered. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|