hook_preprocess().
// Social share icons.
if($hook == 'node') {
if($vars['node']->getType() == 'resource') {
global $base_root;
$vars['base_root'] = $base_root;
//
$site_name = \Drupal::config('system.site')->get('name');
$vars['site_name'] = $site_name;
}
}
.html.twig
{% set node_title = node.getTitle() | url_encode %}
{% set social_url = base_root ~ url %}
{% set summary = content.body[0]['#text']|striptags %}
{% set summary_url = summary|length > 140 ? summary|url_encode|slice(0, 140) ~ '...' : summary %}
<div class="container social">
<div class="service-links">
<a href="http://www.facebook.com/sharer.php?u={{ social_url }}&t={{ node_title }}"
title="Share on Facebook"
class="service-links-facebook"
rel="nofollow">Facebook</a>
<a href="http://twitter.com/share?url={{ social_url }}&text={{ node_title }}"
title="Share this on Twitter"
class="service-links-twitter"
rel="nofollow">Twitter</a>
<a href="http://www.linkedin.com/shareArticle?mini=true&url={{ social_url }}&title={{ node_title }}&summary={{ summary_url }}&source={{ site_name|url_encode }}"
title="Publish this post to LinkedIn"
class="service-links-linkedin"
rel="nofollow">LinkedIn</a>
</div>
</div>