// To create a reliable string of page tags to use for comparison in Liquid conditional statements, place this in layout.html between the and : {% assign tags_list = "" %} {% for tag in page.tags %} {% assign tags_list = tag.name | append: ", " | append: tags_list %} {% endfor %} // We'll need a consistent tag naming convention that contains a 'trigger' phrase and an 'id' to use in the link to the embedded widget. // In this case, we need an ID for a Phone2Action widget, so we'll be using the tag format 'p2a-12345' // // In the page template, we'll loop through the tags, scope the loop to only tags with the 'trigger' phrase, and then split that tag on the delimiter: {% if tags_list contains "p2a-" %} {% for tag in page.tags %} {% if tag.name contains "p2a-" %} {% assign p2a_widget_code = tag.name | split:'-' %} p2a[0]:{{ p2a_widget_code[0] }}
p2a[1]:{{ p2a_widget_code[1] }}
{% endif %} {% endfor %} {% endif %} // Once you have the ID in mind, insert it into your widgets embed markup, a la: p2a embed code:
// Because page tags are printed at the bottom of some pages via `{% include "page_tags" with page %}`, we'll want to prevent widget tags from being printed in this list. // In _page_tags.html, wrap the tag forloop with a conditional to exclude tags that include the 'p2a' prefix: {% for tag in page_tags.tags %} {% unless tag.name contains "p2a-" %} {{ tag.name }} {% endunless %} {% endfor %}