Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi there,
I'm relatively new to Liquid but quite comfortable editing some basic stuff/changing settings files but something really stumped me today and im sure there is an easy explanation!
I have a block that has an <a> over the whole thing but I want to add the ability for up to 3 buttons within the block to look like this:
The settings json is all fine, removing a link removes the button etc but I cannot add individual links to them without breaking the whole layout!
They appear linked but just don't go anywhere essentially.
The individual text/buttons are added like this:
{%- if block.settings.link_2 != blank and block.settings.button_text_2 != blank -%}
<span class="promo-block__cta button button_2--floating">{{ block.settings.button_text_2 | escape }}</span>
{% endif %}
But trying something like the below doesnt work? Simply using {{block.settings.link_2}} adds the URL to the button so i'm confused to what i'm doing wrong here!
{%- if block.settings.link_2 != blank and block.settings.button_text_2 != blank -%}
<span class="promo-block__cta button button_2--floating"><a href="{{block.settings.link_2}}"{{ block.settings.button_text_2 | escape }}</span></a>
{% endif %}
Solved! Go to the solution
This is an accepted solution.
..turns out it was an <a> at the top of the block.
I replaced this with a div, adding a closing div to the very bottom and adding the <a> to each button.
Seems obvious now but in case this helps anyone else!
Equally, variation on this dont seem to work either, although similar is used for linkng up the main image?
{%- if block.settings.link_2 != blank and block.settings.button_text_2 != blank -%}
<a {% if block.settings.link_2 %}href="{{ block.settings.link_2 }}" {% endif %} class="promo-block__cta button button_2--floating">{{ block.settings.button_text_2 | escape }}</span></a>
{% endif %}
This is an accepted solution.
..turns out it was an <a> at the top of the block.
I replaced this with a div, adding a closing div to the very bottom and adding the <a> to each button.
Seems obvious now but in case this helps anyone else!
Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025Expand into selling wholesale with Shopify Academy’s learning path, B2B on Shopify: Lau...
By Shopify Jan 28, 2025