Thanks, @alyssamwilie for this great solution.
@HGriffiths to create this custom module:
- In Marketing->Files and Templates->Design Tools. Find your Custom Modules folder in the left sidebar.
- In the left sidebar select File->New file in “custom modules”
- From the “What would you like to build today” dropdown select Module then Next.
- On the next screen, “where would you like to use this module”, select Emails
- Select local module (global modules are intended to be used where changes to module contents should update all instances of the module across all emails)
- Give the module a file name. e.g. email social share
- Paste the code below (which I tweaked slightly) in the code pane.
<div class="social-share">
{% for social in module.social_item %}
{% set platform = social.platform %}
{% set image = "<img src='" + social.image.src + "' alt='" + social.image.alt + "' />" %}
{% if platform == "facebook" %}
{% set url = "https://www.facebook.com/sharer/sharer.php?u=" + view_as_page_url %}
{% elif platform == "twitter" %}
{% set url = "https://twitter.com/intent/tweet?url=" + view_as_page_url + "&text" + social.text %}
{% elif platform == "linkedin" %}
{% set url = "http://www.linkedin.com/shareArticle?mini=true&url=" + view_as_page_url + "&title=" + social.text %}
{% elif platform == "pinterest" %}
{% set url = "http://pinterest.com/pin/create/button/?url=" + view_as_page_url + "&description=" + social.text %}
{% endif %}
<a href="{{ url }}">{{ image }}</a>
{% endfor %}
</div>
- Now on the right side of the design manager window, we need to create a group of repeating fields to match the field variables we are using in our code. These fields are what will allow you to enter social image and text values when creating your email and using the social share module:
Field Group (Click Group - when creating this group make sure to toggle ‘Repeater Options’ on )
social_item (make sure the label value is exactly this to match the code above)
Fields (now we have our group click add field and the following fields making sure the label are exactly these values to match our code above)
platform
image
text - Now publish the module and in your email editor content sidebar add the new module (under + more in the drag and drop editor.)
- When you click on this module it should now say Social Item and display an +Add link, click this link to start populating platform, image, and test values.
Note: This module creates sharing links using the email’s web version link, so you have to enable web version under the email’s settings. If you wanted to share some other link you could hardcode it by replacing " + view_as_page_url + " with an actual URL in the code above, or create a new link field in your module to allow you to choose the link to share when adding module options e.g create a link field in our field group called link (with a label value of link) and in the code above replace " + view_as_page_url + " with *" + social.link.url.href + "
*


