SVG map-based navigation for Craft CMS. More info: http://localhost/_pog/craft-snippets-craft/web/articles/creating-map-based-navigation-in-craft-cms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# settings #} | |
{% set map = include('usa.svg') %} | |
{% set mapLinks = entry.mapLinks.all() %} | |
{# logic #} | |
{% set map = map|retconRemove('style') %} | |
{% set regionsUsed = [] %} | |
{% for link in mapLinks %} | |
{% if link.linkRegion is not empty and link.linkEntry.exists() and link.linkRegion not in regionsUsed %} | |
{% set regionsUsed = regionsUsed|merge([link.linkRegion]) %} | |
{% set linkRegion = link.linkRegion|upper %} | |
{% set linkUrl = link.linkEntry.one().url %} | |
{% set map = map|retconWrap( 'path#'~linkRegion, 'a#link-'~linkRegion ) %} | |
{% set map = map|retconAttr( 'a#link-'~linkRegion, { 'href' : linkUrl } ) %} | |
{% endif %} | |
{% endfor %} | |
{# output #} | |
{{map|raw}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment