Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

js in tpl

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 07-08-2015, 08:36 AM
 
cvaughan02 cvaughan02 is offline
 

Member
  
Join Date: Mar 2014
Location: st. louis, mo
Posts: 22
 

Default js in tpl

hey guys,

I'm trying to figure out how to add js (specifically json) to a tpl file. in xc4 I just used {literal}{/literal}, but that appears not to work here. how do I add a json string to the js in a tpl without triggering flexy to want to parse it?
__________________
SEEK HAPPINESS. EVERYTHING ELSE IS DETAILS.
Reply With Quote
  #2  
Old 07-08-2015, 09:02 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: js in tpl

You need to do it with custom module - this should help http://kb.x-cart.com/display/XDD/Developer+docs
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 07-08-2015, 09:15 AM
 
cvaughan02 cvaughan02 is offline
 

Member
  
Join Date: Mar 2014
Location: st. louis, mo
Posts: 22
 

Default Re: js in tpl

Quote:
Originally Posted by cflsystems
You need to do it with custom module - this should help http://kb.x-cart.com/display/XDD/Developer+docs


I already have a custom module. my code is in my custom module. the issue is that inside the tpl I need to add a json string:


window._fbq.push(['track', '00000000000000', {'value':'0.00','currency':'USD'}]);


which obviously is wrapped in {} so it's getting interpreted.
__________________
SEEK HAPPINESS. EVERYTHING ELSE IS DETAILS.
Reply With Quote
  #4  
Old 07-08-2015, 09:21 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: js in tpl

Don't put it in tpl file, make a class to return it. That way flexy is not involved in outputting the code, only to call the class and print out the return whatever it is.
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #5  
Old 07-08-2015, 09:27 AM
 
cvaughan02 cvaughan02 is offline
 

Member
  
Join Date: Mar 2014
Location: st. louis, mo
Posts: 22
 

Default Re: js in tpl

Quote:
Originally Posted by cflsystems
Don't put it in tpl file, make a class to return it. That way flexy is not involved in outputting the code, only to call the class and print out the return whatever it is.

that just seems like overkill to drop some fb code on a page. it's the one thing I really don't like about xc5. I'm gonna call that option 2 lol.. thanks for the feedback

does flexy not have an equivalent to smarty's {literal} tag?
__________________
SEEK HAPPINESS. EVERYTHING ELSE IS DETAILS.
Reply With Quote
  #6  
Old 07-08-2015, 09:41 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: js in tpl

Yes there is a lot of going back and forth between tpl and php files in XC5. I am not sure if this is just the way XC5 is coded to work or this is a result of using MVC model, Doctrine and flexy. It is overkill and confusing but it is the way to do it. I don't believe flexy has alternative to smarty's literal tag
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote

The following user thanks cflsystems for this useful post:
cherie (07-17-2015)
  #7  
Old 07-08-2015, 09:50 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: js in tpl

Flexy usually ignores JavaScript. But sometimes I've had to format it "correctly". By that I mean:

This will get mangled by Flexy:
Code:
jQuery(document).ready(function(){$("p").click(function(){$(this).hide();});});

And this won't:
Code:
jQuery(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); });

I'm not sure if that is true with those exact snippets, just using them as an example.

You could try:
Code:
window._fbq.push( [ 'track', '00000000000000', { 'value':'0.00', 'currency':'USD' } ] );
As odd as it seems, I've seen this kind of change make a difference.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote

The following 3 users thank totaltec for this useful post:
cflsystems (07-08-2015), cvaughan02 (07-08-2015), Scott Godin (09-28-2015)
  #8  
Old 07-08-2015, 10:00 AM
 
cvaughan02 cvaughan02 is offline
 

Member
  
Join Date: Mar 2014
Location: st. louis, mo
Posts: 22
 

Default Re: js in tpl

Quote:
Originally Posted by totaltec
You could try:
Code:
window._fbq.push( [ 'track', '00000000000000', { 'value':'0.00', 'currency':'USD' } ] );
As odd as it seems, I've seen this kind of change make a difference.


OMG! Mike, you rock so much! that did it!
__________________
SEEK HAPPINESS. EVERYTHING ELSE IS DETAILS.
Reply With Quote

The following user thanks cvaughan02 for this useful post:
totaltec (07-09-2015)
  #9  
Old 07-08-2015, 10:10 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: js in tpl

That is odd. So flexy goes line by line completely ignoring next/prev lines and caring only about the current one...
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #10  
Old 07-08-2015, 11:05 AM
  wjbrewer's Avatar 
wjbrewer wjbrewer is offline
Banned
 

X-Adept
  
Join Date: Feb 2005
Location: Pittsburgh, PA
Posts: 504
 

Default Re: js in tpl

It's the whitespace, for example:

{data} is parsed

{ data } isn't

Code:
window._fbq.push(['track','00000000000000',{ 'value':'0.00','currency':'USD' }]);
should also work.
Reply With Quote

The following 3 users thank wjbrewer for this useful post:
cherie (07-17-2015), Scott Godin (09-28-2015), totaltec (07-09-2015)
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:56 AM.

   

 
X-Cart forums © 2001-2020