Conversation
This was referenced Feb 19, 2026
|
Does this also work for inline conditional styles using <nav
aria-label="Main navigation"
class="hidden grid-cols-[1fr_max-content_1fr] [grid-template-areas:'left_center_right'] gap-12 h-full lg:grid
{% if header_width == 'page' %} container mx-auto {% else %} px-6 {% endif %}
{% if header_spacing == 'compact' %} min-h-8.5 {% else %} min-h-10.5 {% endif %}
{% if header_text_style == 'uppercase' %} uppercase {% endif %}
"
>
// ... nav code
</nav> |
Author
|
Nope. For this you will probably need to capture first the class and then output it: {% capture class %}
hidden grid-cols-[1fr_max-content_1fr] [grid-template-areas:'left_center_right'] gap-12 h-full lg:grid
{% if header_width == 'page' %} container mx-auto {% else %} px-6 {% endif %}
{% if header_spacing == 'compact' %} min-h-8.5 {% else %} min-h-10.5 {% endif %}
{% if header_text_style == 'uppercase' %} uppercase {% endif %}
{% endcapture %}
<nav aria-label="Main navigation" class="{{ class | squish }}">
// ... nav code
</nav> |
|
Completely agree this is needed (the Horizon whitespace issue is a real headache sometimes) and this is a nice easy elegant solution. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
This PR provides a clean solution to #2040
This PR answers a common use case we're facing with Shopify themes. As themes now become more complex, it is often needed to compose classes or inline styles, for instance using capture tags:
{% capture styles %} --foo: {% if section.settings.foo %}10%{% else %}20%{% endif %}; --bar: 10px; {% endcapture %}This, however, messes with whitespace. While this technically works, this makes it harder to debug. Horizon (Shopify free theme), especially, has this problem:
There are workarounds but they are fragile:
This PR adds a new filter. The name follows the one from Ruby on Rails (https://api.rubyonrails.org/classes/String.html#method-i-squish) and offers a simple, elegant solution:
I've signed the CLA. The associated documentation PR is #2051