How do I use Smarty inside JavaScript code?

Discussion in 'Troubleshooting' started by jocke72, Apr 7, 2009.

  1. jocke72

    jocke72 New Member

    Joined:
    Apr 23, 2007
    Messages:
    8
    Smart is not getting parsed when I do something like this in a .html-file:

    <script type="text/javascript">
    alert({$smarty.session._amember_login});
    </script>

    I simply get a JS error:
    Error: missing : after property id
    Line: 29, Column: 14
    Source code:
    alert({$smarty.session._amember_login});


    Looking at the source, the smarty code isn't parsed.
    It works fine when placed outside a JS-block.


    Thanks!


    /J
  2. codeispoetry

    codeispoetry aMember Pro Customer

    Joined:
    Jan 12, 2009
    Messages:
    336
    Hi J,

    Not possible. Smarty doesn't parse Javascript here.

    Lee
  3. sellers_circle

    sellers_circle New Member

    Joined:
    Oct 8, 2008
    Messages:
    10
    I thought you could use {/literal}{literal}

    <SCRIPT language="javascript" src="http://www.xxxxxxxxxxx.com/redirconsume.aspx?CID=17107&UID={/literal}{$payment.payment_id}{literal}"></SCRIPT>

    Its sort of wierd though as I had to have them as show not {literal}{/literal} and also I been trying to add a new pixel code onto the page using an if statment and it does not work it is formated like this

    {if $payment.product_id eq "20"}
    <iframe src="https://www.xxxxxxx.com/track.frame.php?g=9144&o={/literal}{$payment.payment_id}{literal}" height="1" width="1" frameborder="0"><script language="JavaScript" src="https://www.xxxxxxx.com/trackjs/g-9144/o-{/literal}{$payment.payment_id}{literal}"track.js"></script><noscript><img src="https://www.lynxtrack.com/track.php?g=9144&o={$payment.payment_id}" width="1" height="1" border="0"></noscript></iframe>

    {/if}

    and it does not work infact it throws an error on the thanks.html page

Share This Page