I have a sample code: in .php
STemplate::assign('image', 'test.png');
in .tpl
{literal}
<script type="text/javascript">
var image_src = {$image};
alert(image_src);
</script>
{/literal}
How to fix it?
Your { are not working as smarty code, because you are in a literal block. You can break out of it like so:
{literal}
<script type="text/javascript">
var image_src = '{/literal}{$image}{literal}';
alert(image_src);
</script>
{/literal}
or, as you are not using { in javascript, do this
<script type="text/javascript">
var image_src = '{$image}';
alert(image_src);
</script>
I've also added some ' I think you need.
{ in the javascript, you can use {ldelim} when not using {literal} by the way)You can solve your problem below 3 ways
1.
{literal}
<script type="text/javascript">
function myFunc(){
var image_src = {/literal}{$image}{literal};
alert(image_src);
}
</script>
{/literal}
2.
<script type="text/javascript">
function myFunc(){ldelim}
var image_src = {$image};
alert(image_src);
{rdelim}
</script>
3.
<script type="text/javascript">
var myImage = {$image}
{literal}
function myFunc(){
var image_src = myImage;
alert(image_src);
}
{literal}
</script>
"{$image}";so that the javascript parser will seetest.pngas a string and not some javascript statement