X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Escaping { in custom module code (https://forum.x-cart.com/showthread.php?t=70200)

haleystudio 10-09-2014 11:45 AM

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!

cflsystems 10-09-2014 11:56 AM

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>

haleystudio 10-09-2014 02:37 PM

Re: Escaping { in custom module code
 
Oh, just like in X-Cart 4. I forget so soon! :-) Thanks, I'll give it a try.

cflsystems 10-09-2014 02:40 PM

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

totaltec 10-09-2014 04:22 PM

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?

haleystudio 10-10-2014 05:50 AM

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
{
\{
{{
{{{

tony_sologubov 10-14-2014 11:42 AM

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.

haleystudio 10-14-2014 12:04 PM

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.

tony_sologubov 10-14-2014 12:30 PM

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.

totaltec 10-14-2014 06:12 PM

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.

haleystudio 10-15-2014 07:36 AM

Re: Escaping { in custom module code
 
Okay, getting really close! New output:

(snip) publisher:& # 039; (snip)
How do I make flexy not encode my quotes into & # 039; ? (spaces added so it won't encode here)

tony_sologubov 10-15-2014 08:16 AM

Re: Escaping { in custom module code
 
Aw, you should call your getShareCode() method in template like this {getShareCode():h} as Flexy encodes special chars by default. :h modifier disables such encoding.

haleystudio 10-15-2014 09:05 AM

Re: Escaping { in custom module code
 
Aha! That worked great. The code for the Newsletter (MailChimp) section looks like it's working like it should.

One last tiny thing. I have the code looking great in the source view. But the icons are not displaying on the site (they are drawn by the script).
EDIT: they are showing up in Safari, not Firefox or IE (all on PC). But the links don't seem to work well on Safari. /EDIT

Site: https://7sorrowsrosaries.com/ -- section is "Share this page" on the bottom of the left column.

I put the exact same code on a test page, here: (no compiler, this is straight html) http://haleystudio.com/script-test.html and it works fine (links work too).

AND -- get this -- when I saved the page from 7sorrowsrosaries.com as "save as full web page" and then previewed it, without changes, in the same browser, NO PROBLEM. Can't tell if the links are working from there... but at least the icons are displaying. Here's the screenshot.

http://haleystudio.com/images/clients/share-gif.gif

totaltec 10-15-2014 11:55 AM

Re: Escaping { in custom module code
 
I think the buttons do not display, because you have included an http: reference to the script, and the link to the page above is https.

haleystudio 10-16-2014 05:13 AM

Re: Escaping { in custom module code
 
Okay! Thank you all SO MUCH.

It's still not working great -- but from here on I think it's a Javascript thing vs. an X-Cart thing, so I'll take those troubles elsewhere!


All times are GMT -8. The time now is 05:19 AM.

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