ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Need help getting JS and EE to play nice

September 17, 2011 1:03pm

Subscribe [2]
  • #1 / Sep 17, 2011 1:03pm

    Doug E

    98 posts

    I’m using AddThis to share entries on my site. It works fine for the most part, however if I want to use their Twitter template to customize what shows up in the tweets I’m having issues.

    It says to use the following code:

    [script]
    var addthis_share = {
        templates: {
        twitter : "{{title}} {{url}} from @uscwmMF"
        }
    }
    [script]
            
    <!-- AddThis Button BEGIN -->
    <div class="addthis_toolbox addthis_default_style addthis_32x32_style"
        addthis:url="{url_title_path="issue/article"}"
        addthis:title="{title}"
        addthis:description="{mf-sharing-text}">
        <a class="first addthis_button_facebook"></a>
        <a class="addthis_button_twitter"></a>
        <a class="addthis_button_email"></a>
        <a class="last addthis_button_compact"></a>
    </div>
    <!-- AddThis Button END -->

    The {{url}} and {{title}} are supposed to be filled with the values I specify in addthis:url and addthis:title. However What I get is:
    } from @uscwmM

    It seems that EE is rendering the {{url}} and {{title}} parts of the script. How do I get EE to leave them alone and render them as is so the script can do its thing and fill them with the proper values? The support guy at Addthis suggest escaping the {{ characters, but what I tried didn't work.

    I've looked around and found this thread that seems to be related to the same issue. I’ tried the config file modification. I’m using 2.2.1 20110630(do need to update, but can’t right now).

  • #2 / Sep 17, 2011 10:23pm

    John St-Amand

    865 posts

    I’m just guessing a little here, but you could try inserting the add this button with an embed and passing it the values you need in the embed code - that way the values are parsed before the addthis javascript.

    So something like:

    {embed="your_embed_template_group/dynamic_add_this_embed_template" the_title="{title}" the_url="{url}"}

    And then in the embedded template, you use {embed:the_title} and {embed:the_url} within the add this javascript.

    At least that’s what I would try because I believe it’s parse order that’s affecting your javascript.  The buttons themselves ought to be fine.  Hope that helps.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases