|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ehunt123 Smarty n00b
Joined: 12 Dec 2014 Posts: 2
|
Posted: Fri Dec 12, 2014 8:00 pm Post subject: Issue with javascript function not being run in a template |
|
|
Hi,
A product we use has Smarty interpreting each page it's on. I am trying to inject the Google Trusted Merchant code as you'll see in the code below. We're also trying to autogen the estimated ship date. My code works outside of Smarty but I cannot get the value to be "generated" when it runs the template.
This is what the source is when it's rendered:
http://pastebin.com/sk4xM6DF
As you can see, it's literally printing the Javascript instead of computing the code.
Any suggestions?
Thanks.
Code: |
{literal}
<script type="text/javascript">
function getBusinessDays(days){
var cDate = new Date();
for (var i = 1; i <= days ; i++){
var counter = 1;
cDate.setDate(cDate.getDate() + counter);
if (cDate.getDay() == 6 || cDate.getDay() == 0)
days++;
}
var fDate = cDate.getFullYear()+'-'+cDate.getMonth()+'-'+cDate.getDate()
return fDate;
}
</script>
<!-- START Google Trusted Stores Order -->
<div id="gts-order" style="display:none;" translate="no">
<!-- start order and merchant information -->
<span id="gts-o-id">{$placed.order.id}</span>
<span id="gts-o-domain"></span>
<span id="gts-o-email">{$placed.info.billing.email}</span>
<span id="gts-o-country">US</span>
<span id="gts-o-currency">{$placed.info.currency_type}</span>
<span id="gts-o-total">{$placed.totals.grandtotal}</span>
<span id="gts-o-discounts">ORDER_DISCOUNTS</span>
<span id="gts-o-shipping-total">{$placed.totals.shiptotal}</span>
<span id="gts-o-tax-total">{$placed.totals.taxtotal}</span>
<span id="gts-o-est-ship-date">
<script type="text/javascript">
document.write(getBusinessDays(5));
</script>
</span>
<span id="gts-o-est-delivery-date">ORDER_EST_DELIVERY_DATE</span>
<span id="gts-o-has-preorder">N</span>
<span id="gts-o-has-digital">N</span>
<!-- end order and merchant information -->
<!-- start repeated item specific information -->
<!-- item example: this area repeated for each item in the order -->
<span class="gts-item">
<span class="gts-i-name">ITEM_NAME</span>
<span class="gts-i-price">ITEM_PRICE</span>
<span class="gts-i-quantity">ITEM_QUANTITY</span>
<span class="gts-i-prodsearch-id">ITEM_GOOGLE_SHOPPING_ID</span>
<span class="gts-i-prodsearch-store-id">ITEM_GOOGLE_SHOPPING_ACCOUNT_ID</span>
<span class="gts-i-prodsearch-country">ITEM_GOOGLE_SHOPPING_COUNTRY</span>
<span class="gts-i-prodsearch-language">ITEM_GOOGLE_SHOPPING_LANGUAGE</span>
</span>
<!-- end item 1 example -->
<!-- end repeated item specific information -->
</div>
<!-- END Google Trusted Stores Order -->
{/literal}
| [/code] |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Dec 12, 2014 10:57 pm Post subject: |
|
|
You didn't seem to have understood documentation very well.
The {literal} block is completely excluded from parsing. Beside that, you don't need to use it. |
|
Back to top |
|
ehunt123 Smarty n00b
Joined: 12 Dec 2014 Posts: 2
|
Posted: Sat Dec 13, 2014 1:29 am Post subject: |
|
|
AnrDaemon wrote: | You didn't seem to have understood documentation very well.
The {literal} block is completely excluded from parsing. Beside that, you don't need to use it. |
Hi,
I updated it but still don't see it executing. I ran it inside w/Firebug and don't see any errors thrown, but the date is not appearing:
Code: | <script type="text/javascript">
{literal}
function getBusinessDays(days){
var cDate = new Date();
for (var i = 1; i <= days ; i++){
var counter = 1;
cDate.setDate(cDate.getDate() + counter);
if (cDate.getDay() == 6 || cDate.getDay() == 0)
days++;
}
var fDate = cDate.getFullYear()+'-'+cDate.getMonth()+'-'+cDate.getDate()
return fDate;
}
{/literal}
</script>
<!-- START Google Trusted Stores Order -->
<div id="gts-order" style="display:none;" translate="no">
<!-- start order and merchant information -->
<span id="gts-o-id">{$placed.order.id}</span>
<span id="gts-o-domain"></span>
<span id="gts-o-email">{$placed.info.billing.email}</span>
<span id="gts-o-country">US</span>
<span id="gts-o-currency">{$placed.info.currency_type}</span>
<span id="gts-o-total">{$placed.totals.grandtotal}</span>
<span id="gts-o-discounts">ORDER_DISCOUNTS</span>
<span id="gts-o-shipping-total">{$placed.totals.shiptotal}</span>
<span id="gts-o-tax-total">{$placed.totals.taxtotal}</span>
<span id="gts-o-est-ship-date">
<script type="text/javascript">
document.write(getBusinessDays(5));
</script>
</span>
<span id="gts-o-est-delivery-date">ORDER_EST_DELIVERY_DATE</span>
<span id="gts-o-has-preorder">N</span>
<span id="gts-o-has-digital">N</span>
<!-- end order and merchant information -->
<!-- start repeated item specific information -->
<!-- item example: this area repeated for each item in the order -->
<span class="gts-item">
<span class="gts-i-name">ITEM_NAME</span>
<span class="gts-i-price">ITEM_PRICE</span>
<span class="gts-i-quantity">ITEM_QUANTITY</span>
<span class="gts-i-prodsearch-id">ITEM_GOOGLE_SHOPPING_ID</span>
<span class="gts-i-prodsearch-store-id">ITEM_GOOGLE_SHOPPING_ACCOUNT_ID</span>
<span class="gts-i-prodsearch-country">ITEM_GOOGLE_SHOPPING_COUNTRY</span>
<span class="gts-i-prodsearch-language">ITEM_GOOGLE_SHOPPING_LANGUAGE</span>
</span>
<!-- end item 1 example -->
<!-- end repeated item specific information -->
</div>
<!-- END Google Trusted Stores Order -->
|
|
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Tue Dec 16, 2014 5:12 am Post subject: |
|
|
was that the code that is served to your browser? if not, what code is served to your browser? |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|