kushalbhaktajoshi
kushalbhaktajoshi

Reputation: 4678

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

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.

Upvotes: 5

Views: 9203

Answers (3)

GMO
GMO

Reputation: 669

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

Upvotes: 3

Thilak
Thilak

Reputation: 590

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.

Upvotes: 0

mailo
mailo

Reputation: 2611

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

Upvotes: 18

Related Questions