I think no only

    <?php $share = module_invoke('addtoany', 'block_view', 'addtoany_button');
          print render($share['content']); ?>

is required.

If I just embedding block in my template, many other rows of code aren't uppearing:

in header:

@import url("http://mysite/sites/all/modules/addtoany/addtoany.css");

<script type="text/javascript">
<!--//--><![CDATA[//><!--
var a2a_config=a2a_config||{},da2a={done:false,html_done:false,script_ready:false,script_load:function(){var a=document.createElement('script'),s=document.getElementsByTagName('script')[0];a.type='text/javascript';a.async=true;a.src='http://static.addtoany.com/menu/page.js';s.parentNode.insertBefore(a,s);da2a.script_load=function(){};},script_onready:function(){da2a.script_ready=true;if(da2a.html_done)da2a.init();},init:function(){for(var i=0,el,target,targets=da2a.targets,length=targets.length;i<length;i++){el=document.getElementById('da2a_'+(i+1));target=targets[i];a2a_config.linkname=target.title;a2a_config.linkurl=target.url;if(el)a2a.init('page',{target:el});da2a.done=true;}}};a2a_config.tracking_callback=['ready',da2a.script_onready];
//--><!]]>
</script>

in footer:

<script type="text/javascript">
<!--//--><![CDATA[//><!--
da2a.targets=[
{title:'my page title',url:'http://mysite/mypage'}];
da2a.html_done=true;if(da2a.script_ready&&!da2a.done)da2a.init();da2a.script_load();
//--><!]]>
</script>

how can I embed a block with all this rows of code automatically? May be some magic in template.php?

Comments

LoyC’s picture

I need this to

sgurlt’s picture

Subscribing !

Jovean’s picture

Try adding this to your code just before the module_invoke:

global $_addtoany_init;
$_addtoany_init = TRUE;
Jody Lynn’s picture

Comment 3 is useful.

I use the following hook_init implementation to make sure this is set on my nodes, allowing me cache the pages.

function mymodule_init() {
  if ($node = menu_get_object() && arg(2) == NULL) {
    global $_addtoany_init;
    $_addtoany_init = TRUE;
  }
}
hugues.esslinger’s picture

I try Comment 3 and 4...

But not working for me...

Can I forced to load add to any and initializ it ?

atif.kht’s picture

Can anyone post a complete solution to this one?

standingtall’s picture

subscribing!!

rooby’s picture

For people where this isn't working for you are you using version 3 or version 4 of the module?

If version 3 you should update to version 4 because 3 is not supported any more.

Version 4 really should work without you having to do anything unusual like set global variables but I will try it out when I get a chance and see.

permanaj’s picture

I'm using version 4. Tried #3 also not working.
At first call, it shows, but after I do some configruation, it didn't show anymore.

NIKS_Artreaktor’s picture

Interesting thing.

If you create the same addtoany block content
But change style
a2a_target
to
a2a_default_style

It is working - even if you create simple html code of generated addtoany list.

maxf4’s picture

On my new site drupal 7
I workaround the issue simply adding this code in my node type

<div class="a2a_kit a2a_kit_size_32 a2a_default_style">
    <a class="a2a_button_facebook"></a>
    <a class="a2a_button_twitter"></a>
    <a class="a2a_button_google_plus"></a>
    <a class="a2a_button_pinterest"></a>
    <a class="a2a_dd" href="https://www.addtoany.com/share"></a>
</div>

<script async src="https://static.addtoany.com/menu/page.js"></script>

this works!
Hope could be of help for someone

halth’s picture

Make sure you're rendering $page['content']; to the node's corresponding page template file:

print render($page['content']);

Addtoany attaches it's javascripts to the page's (not node's) content element:

function addtoany_page_alter(&$page) {
  // ...  

  $page['content']['#attached']['js'][] = array(
    'data'  => $javascript_header,
    'scope' => 'header',
    'type'  => 'inline',
  );

  $page['content']['#attached']['js'][] = array(
    'data'  => $javascript_footer,
    'scope' => 'footer',
    'type'  => 'inline',
  );

  // ...
}
micropat’s picture

Status: Active » Closed (outdated)