Passing a Smarty variable into Javascript link “sr

2020-08-01 04:34发布

问题:

I've assigned a Smarty variable:

{assign var="siteurl" value="http://website.com"}

I can successfully use it in my header.html file to call a CSS link:

<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}":

<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?

回答1:

Problem Solved! As mentioned in the comments above, I am working on an aMember system. 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. 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. I have to manually put the code above for each javascript src instance.

THANK YOU SO MUCH EVERYONE FOR THE HELP!!



回答2:

Are the script tags wrapped in a Smarty {literal}{/literal} block? That would prevent rendering of the {$siteurl} tag.