I have a custome template made (node..template.tpl.php) do display a custom content type named template.

What is the php code to print the sharethis links on this file?

Drupal7

Comments

Gaofengzzz’s picture

You can try to use

<?php print theme('sharethis', array('data_options' => sharethis_get_options_array(), 'm_path' => 'your_path', 'm_title' => 'your_title')); ?>

in template file.

Gaofengzzz’s picture

Status: Active » Fixed
spv’s picture

Nope didnt print anything actually.... any other thoughts?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

spv’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

Posted this over a year ago never found a solution..... how do we paste the share this code in a custom page template so that it shares that exact page.....

leidyran’s picture

I guest you can try the following:

$node = node_load($nid);
$links = sharethis_node_view($node, 'full', 'en');
print('

'.$node->content['sharethis']['#value'].'

');

glewe’s picture

Just use this (Drupal 7):
<?php print render($content['sharethis']); ?>

Rishi Kulshreshtha’s picture

Version: 7.x-2.5 » 7.x-2.x-dev

For Drupal 8 just use:

{{ content.sharethis }}

to print the sharethis widget via your node.html.twig or similar.

lejager’s picture

#6 by leidryan worked for me.

Here's an example in a THEME_preprocess_page(), adding the share links to the sidebar.

function THEME_preprocess_page(&$vars) {
  $node = node_load($vars['node']->nid);
      if ($node) {
        $links = sharethis_node_view($node_object, 'full', 'en');
        if (!empty($node_object->content['sharethis']['#value'])) {
          $vars['page']['sidebar_first']['sharethis'] = array(
            '#prefix' => '<div class="sharethis-buttons"><h4 class="block-title--secondary">Share</h4>',
            '#markup' => $node->content['sharethis']['#value'],
            '#suffix' => '</div>',
            '#weight' => 3,
          );
        }
      }
AswathyAjish’s picture

#1 worked for me. Thanks.