Send javascript to footer with Smarty
Problem: neat loading of javascript files in footer. Question: do you have any metho开发者_JAVA百科d or do you know a method to do this ellegantly with smarty?
I can imagine assigning arrays at tpl runtime and make a foreach in footer.tpl that neatly renders them. I can aslo imagine a whole helper or object in that matter.
What do you recommend?
The first way you suggested is actually how I do it. And I'm quite satisfied that way.
PHP:
$loadJSFiles = array();
$loadJSFiles[] = 'file1.js';
$loadJSFiles[] = 'file2.js';
$smarty->assign('loadJSFiles', $loadJSFiles);
Template:
{foreach $loadJSFiles as $val}
<script type="text/javascript" src="{$val}"></script>
{/foreach}
精彩评论