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

Escaping { in custom module code

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 10-09-2014, 11:45 AM
 
haleystudio haleystudio is offline
 

Member
  
Join Date: Oct 2014
Posts: 14
 

Red face Escaping { in custom module code

So I figured out how to make a new module
(http://kb.x-cart.com/display/XDD/Creating+sidebar+menu+in+customer+area was a good guide).

I am using my sidebar module to display some code from MailChimp - a newsletter signup. I would also like to use it to display my sharing icons from ShareThis.com.

However, using { } doesn't work - gets ignored. What's the escape character or some workaround?

HTML Code:
<script type="text/javascript">stLight.options({publisher: "redacted", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>

This may be a very newbie question but I haven't found the answer yet.

Thanks in advance!
__________________
X-Cart Business 5.1.6
Reply With Quote
  #2  
Old 10-09-2014, 11:56 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: Escaping { in custom module code

Either use {literal} tag or replace { } with {ldelim} {rdelim}
Code:
{literal}<script type="text/javascript">stLight.options({publisher: "redacted", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script> {/literal}
Code:
<script type="text/javascript">stLight.options({ldelim}publisher: "redacted", doNotHash: false, doNotCopy: false, hashAddressBar: false{rdelim});</script>
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote

The following user thanks cflsystems for this useful post:
haleystudio (10-09-2014)
  #3  
Old 10-09-2014, 02:37 PM
 
haleystudio haleystudio is offline
 

Member
  
Join Date: Oct 2014
Posts: 14
 

Default Re: Escaping { in custom module code

Oh, just like in X-Cart 4. I forget so soon! Thanks, I'll give it a try.
__________________
X-Cart Business 5.1.6
Reply With Quote
  #4  
Old 10-09-2014, 02:40 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: Escaping { in custom module code

Oh sorry this is for XC5. That won't work. What I said applies to smarty, you have to find the alternative for Flexy
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #5  
Old 10-09-2014, 04:22 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: Escaping { in custom module code

Flexy should be ignoring {} inside of a <script> element. http://pear.php.net/manual/en/package.html.html-template-flexy.attribute.tojavascript.php

Your JS code looks odd to me. Where is the example of proper setup from ShareThis?
__________________
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
  #6  
Old 10-10-2014, 05:50 AM
 
haleystudio haleystudio is offline
 

Member
  
Join Date: Oct 2014
Posts: 14
 

Default Re: Escaping { in custom module code

You can see this straight from sharethis.com. You don't have to specify a site but you do need to log in.

HTML Code:
<script type="text/javascript">var switchTo5x=true;</script> <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script> <script type="text/javascript">stLight.options({publisher: "b4f4f721-de8b-4e2f-8c74-d5175ea04b23", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>


Publisher value was "redacted" in earlier code post.

Sharethis wants the code in the <head> actually. (I'll take advice on how to do that as well...) I have another module (MailChimp) that also needs {'s, not in the <head>.

Things that haven't worked so far (assume the complementary closing tag):
{literal} around script line
{
\{
{{
{{{
__________________
X-Cart Business 5.1.6

Last edited by haleystudio : 10-10-2014 at 05:53 AM. Reason: format
Reply With Quote
  #7  
Old 10-14-2014, 11:42 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Escaping { in custom module code

Hi haleystudio!

You are right, Flexy thinks that {publisher: } is a call of method getPublisher() and that is why omits everything after ':' character.

You can work around this problem if you add method like getShareCode() into your PHP class. This method would return the needed JS code. Then, you should call {getShareCode()} in your template and the JS code will be properly added there.

Tony.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote

The following user thanks tony_sologubov for this useful post:
totaltec (10-14-2014)
  #8  
Old 10-14-2014, 12:04 PM
 
haleystudio haleystudio is offline
 

Member
  
Join Date: Oct 2014
Posts: 14
 

Default Re: Escaping { in custom module code

Actually, what I'm seeing in the "view source" of the web page for that line is
HTML Code:
<script type="text/javascript">stLight.options();</script>
so I think it's ignoring everything inside the {}'s.
__________________
X-Cart Business 5.1.6
Reply With Quote
  #9  
Old 10-14-2014, 12:30 PM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Escaping { in custom module code

Quote:
Originally Posted by haleystudio
Actually, what I'm seeing in the "view source" of the web page for that line is
HTML Code:
<script type="text/javascript">stLight.options();</script>
so I think it's ignoring everything inside the {}'s.

Exactly.

Anyway, approach I suggested above should help.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #10  
Old 10-14-2014, 06:12 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: Escaping { in custom module code

Thanks for helping with this Tony, I forgot about this thread. Tony has the right idea, just put the share code in a method inside the controller class and call it in the template.
__________________
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
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:38 AM.

   

 
X-Cart forums © 2001-2020