[英]Passing a Smarty variable into Javascript link “src” attribute
I've assigned a Smarty variable: 我分配了一个Smarty变量:
{assign var="siteurl" value="http://website.com"}
I can successfully use it in my header.html file to call a CSS link: 我可以在header.html文件中成功使用它来调用CSS链接:
<link rel="stylesheet" type="text/css" href="{$siteurl}/style.css" />
displays 显示
<link rel="stylesheet" type="text/css" href="http://website.com/style.css" />
However, when I do the same for a Javascript source, it literally prints out "{$siteurl}": 但是,当我对Javascript源执行相同操作时,它实际上会打印出“ {$ siteurl}”:
<script type="text/javascript" src="{$siteurl}/scripts.js"></script>
displays 显示
<script type="text/javascript" src="{$siteurl}/scripts.js"></script>
Why isn't this Smarty variable displaying as expected? 为什么此Smarty变量未按预期显示?
Problem Solved! 问题解决了! As mentioned in the comments above, I am working on an aMember system. 如上面的评论中所述,我正在使用aMember系统。 I'm not sure if they leave smarty {literal} tags open at the end of their initial files, and then close them at the end, or what. 我不确定它们是否在其初始文件末尾打开聪明的{literal}标签,然后在末尾关闭它们,或者关闭它们。 But the fix was replacing 但是解决方法正在取代
{$siteurl}
with 与
{/literal}{$siteurl}{literal}
I tried putting the reverse {literal} tags at the beginning and end of the document, but it threw an error. 我尝试将反向{literal}标记放在文档的开头和结尾,但是它引发了错误。 I have to manually put the code above for each javascript src instance. 我必须手动将上述代码用于每个javascript src实例。
THANK YOU SO MUCH EVERYONE FOR THE HELP!! 非常感谢大家的帮助!
Are the script tags wrapped in a Smarty {literal}{/literal}
block? 脚本标签是否包装在Smarty {literal}{/literal}
块中? That would prevent rendering of the {$siteurl}
tag. 那将阻止呈现{$siteurl}
标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.