Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can a smarty variable be made working under {literal}{/literal}

Tags:

php

smarty

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/prototype.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.

like image 537
kushalbhaktajoshi Avatar asked Nov 30 '22 08:11

kushalbhaktajoshi


2 Answers

{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}&lt;script type=&quot;text/javascript&quot; src=&quot;{/literal}{$SITE_URL}{literal}lightbox/js/prototype.js&quot;&gt;&lt;/script&gt;<br>{/literal}
like image 192
mailo Avatar answered Dec 06 '22 07:12

mailo


Another solution is to replace your { and } for the javascript with {ldelim} and {rdelim}. No more need of {literal}.

like image 31
GMO Avatar answered Dec 06 '22 06:12

GMO