Variable values not displaying

68 views
Skip to first unread message

Michael Blower

unread,
Feb 9, 2015, 5:38:04 PM2/9/15
to smarty-d...@googlegroups.com
I"m having trouble getting smarty variable values to display inside a section of javascript.

I'm new to smarty, any assistance would be greatly appreciated.


Code:

{if $view == "checkout_thanks"}
<script type="text/javascript">
var sliSparkJsHost = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + sliSparkJsHost + "b.sli-spark.com/sli-spark.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script language="javascript" type="text/javascript">
var spark= new SliSpark("2534", "1");
spark.setPageType("checkout_thanks");
spark.addTransaction("{$placed.order.id}", "{$memberinfo.id}", "{$placed.totals.grandtotal}", "{$placed.totals.shiptotal}", "{$placed.totals.taxtotal}");
{foreach from=$placed.cart key="key" item="prod"}
   spark.addItem("{$prod.sku}","{$prod.qty}","{$prod.price}");
{/foreach}
{literal}
spark.writeTrackCode();
spark.writeTransactionCode();
</script>{/literal}
{/if}

<br><b>
grandtotal: {$placed.totals.grandtotal}<br>
shiptotal: {$placed.totals.shiptotal}<br>
taxtotal: {$placed.totals.taxtotal}<br></b>



Last three line function but same variables in the middle don't display
<script type="text/javascript">
var sliSparkJsHost = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + sliSparkJsHost + "b.sli-spark.com/sli-spark.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script language="javascript" type="text/javascript">
var spark= new SliSpark("2534", "1");
spark.setPageType("checkout_thanks");
spark.addTransaction("170999", "82217", "", "", "");
spark.writeTrackCode();
spark.writeTransactionCode();
</script>
<br><b>
grandtotal: <br>
shiptotal: <br>
taxtotal: <br></b>

But I get these values from the last three lines of code outsite of the javascript section
grandtotal: 41.17
shiptotal: 10.95
taxtotal: 2.27


variable debug

  - [placed] => Array
        (
          +[cart] => Array
          +[order] => Array
          +[recip] => Array
          +[mappings] => Array
          +[info] => Array
           - [totals] => Array
                (
                  +[totals] => Array
                    [grandtotal] => 85.07
                    [shiptotal] => 20.25
                    [pre_api_shiptotal] => 20.25
                    [taxtotal] => 4.87
                    [subtotal_ship] => 59.95
                    [weight] => 25.8
                    [fixed_ship_weight] => 0
                    [sgroupadd] => 0.00
                    [shipserviceadd] => 0.00
                    [subtotal] => 59.95
                    [gifttotal] => 0.00
                    [gift_certificates] => 0.00
                  +[own_box] => Array
                    [total_addcharge] => 2
                    [total_total_qty] => 2
                    [exclude_prods] => 0
                    [reward_total] => 0
                    [reward_price_total] => 0
                )

            [rewards_points_earned] => 0
            [rewards_points_redeemed] => 0
          +[gift_certificates] => Array
        )


thanks

uwe.tews

unread,
Feb 9, 2015, 7:47:50 PM2/9/15
to smarty-d...@googlegroups.com
During development you should have caching disabled:
$smarty->caching = false;

Make sure that templates get compiled on modifications:
$smarty->compile_check = true;

You may manually delete the compiled/cache files in the templates_c and cache folder to start with a clean setup.

I can't see a problem in your template code.

The variable dump values do not correspond to the sample page output.
Also the array element 'totals' has another subarray with index 'totals'.
Is that correct?

If PHP has a byte cache like APC or ZEND opcache enabled is it configured right to check for file updates on each request?

Currently I have no more ideas.

Michael Blower

unread,
Feb 10, 2015, 12:53:27 PM2/10/15
to smarty-d...@googlegroups.com
Smarty in this case is integrated in to a Content Management System.  I'm able to do a 'publish' once i've gotten it functioning, but don't have access to the back-end php or directory structure to clear cache files.

Its odd the view source on the resulting page does not contain the values that are populating. But the ones that are working are visible from the webpage view.

I'll attempt to use the $smarty->caching=false and $smarty->compile_check=true; statement.  Though I'm unsure how this might effect performance on the live site.

Thanks for the pointers.

The data is at the same level in the first Totals array as the second Totals array, Makes it a bit confusing but It works as I have it when I place the smarty code outside of the <script> </script> tags.  Which seems to point to something other than cache. I need it to function inside the script tags because it makes the script functional.

Michael Blower

unread,
Feb 10, 2015, 1:44:44 PM2/10/15
to smarty-d...@googlegroups.com
Thanks you hint about cache helped, by removing the code in question publishing page and reinserting the code I got the back end to cooperate and I'm getting the values I need now in my section of Javascript.

Thank-you so much!


On Monday, February 9, 2015 at 4:47:50 PM UTC-8, uwe.tews wrote:

Daniel Elvito

unread,
Mar 12, 2015, 10:03:28 PM3/12/15
to smarty-d...@googlegroups.com
{literal}
<script type="text/javascript">
var test={/literal}{$your assign}{literal}
</script>
{/literal}





--
You received this message because you are subscribed to the Google Groups "Smarty Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smarty-develop...@googlegroups.com.
To post to this group, send email to smarty-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/smarty-developers.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages