I have following codes using smarty template engine
In php file:
$smarty->assign('SITE_URL', 'http://localhost/mis/');
In tpl file:
{literal}
<script type="text/javascript" src="{$SITE_URL}lightbox/js/pro开发者_开发知识库totype.js"></script>
<script type="text/javascript" src="{$SITE_URL}lightbox/js/scriptaculous.js?load=effects,builder"></script>;
<script type="text/javascript" src="{$SITE_URL}lightbox/js/lightbox.js"></script>
{/literal}
I want the codes to be rendered like below in html view
<script type="text/javascript" src="http://localhost/mis/lightbox/js/prototype.js"></script>
<script type="text/javascript" src="http://localhost/mis/lightbox/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="http://localhost/mis/lightbox/js/lightbox.js"></script>
Please help me with this.
{literal} is used to prevent variables, so you cannot do it like you described. Instead, you should close {/literal} tag before you want to use a variable.
{literal}<script type="text/javascript" src="{/literal}{$SITE_URL}{literal}lightbox/js/prototype.js"></script><br>{/literal}
Another solution is to replace your { and } for the javascript with {ldelim} and {rdelim}. No more need of {literal}.
Between these two tags {literal}...{/literal} you cant use the smarty variables or php variables. This tags mentioned to smarty compiler, between these two tags codes should be javascript code. So your smarty variables are not working there. If you want need to use the smarty variables / functions you should close the {literal} tag.
精彩评论