X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Accessing Smarty Variable in Javascript?? (https://forum.x-cart.com/showthread.php?t=50112)

lucid 10-09-2009 03:16 AM

Accessing Smarty Variable in Javascript??
 
Hi,

I'm trying to access an extra field value from within javascript. How can I do this??


Here is what I have if it helps, it's take from the customer/main/product.tpl: I'm trying to Alert( {$v.field_value} )


Code:

  {foreach from=$extra_fields item=v}
  {if $v.service_name eq 'Audio_Playlist_Link' }
      {if $v.field_value ne ''}

              <div id="flashPlayer">
                This text will be replaced by the flash music player.
                {$v.field_value}
              </div>
              {literal}
              <script type="text/javascript">
                var so = new SWFObject("http://mindandzen.com/skin1/audio/audioplayer.swf", "audioplayer", "300", "100", "7", "#FFFFFF");


                alert("{$v.field_value}");

                so.addVariable("xmlFile", $v.field_value );
                so.write("flashPlayer");
              </script>
              {/literal}
      {/if}
  {/if}


ambal 10-09-2009 03:40 AM

Re: Accessing Smarty Variable in Javascript??
 
moved to X-Cart Customization > Storefront Design & Template Editing in v3.x, 4.0.x, 4.1.x

geckoday 10-09-2009 06:30 AM

Re: Accessing Smarty Variable in Javascript??
 
The {literal} ... {/literal} means don't do anything smarty between those tags. You have two choices. Since you don't use any { or } in your javascript you can just remove the {literal} and {/literal}. If you think you might be adding in some ifs where you'll be using { and } you can either leave out the {literal} {/literal} and use {ldelim} and {rdelim} instead { and } in your javascript. Or you can leave in the {literal} {/literal} and change
{$v.field_value} to {/literal}{$v.field_value}{literal}.


All times are GMT -8. The time now is 11:16 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.