开发者

Send javascript to footer with Smarty

开发者 https://www.devze.com 2023-03-02 16:35 出处:网络
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?

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}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号