Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquid check should be ignored if contains HTML #704

Open
bakura10 opened this issue Jan 22, 2023 · 0 comments
Open

Liquid check should be ignored if contains HTML #704

bakura10 opened this issue Jan 22, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@bakura10
Copy link

Hi,

As of today, the Liquid tag is actually extremely annoying to use as soon as you have HTML mixed inside the Liquid. Take for instance this code:

{%- if order.shipping_address and fulfillment -%}
            {%- assign created_at = fulfillment.created_at | date: format: 'date' -%}

            {%- if fulfillment.tracking_number -%}
              {%- assign fulfillment_message = 'customer.order.fulfillment_with_number' | t: date: created_at, tracking_number: fulfillment.tracking_number -%}
            {%- else -%}
              {%- assign fulfillment_message = 'customer.order.fulfillment' | t: date: created_at -%}
            {%- endif -%}

            {%- if fulfillment.tracking_url -%}
              {%- capture fulfillment_message -%}
                {%- assign button_content = 'customer.order.track_shipment' | t -%}

                <div class="banner__text-with-button">
                  {{- fulfillment_message -}}
                  {%- render 'button', href: fulfillment.tracking_url, external: true, content: button_content, size: 'sm' -%}
                </div>
              {%- endcapture -%}
            {%- endif -%}

            {%- render 'banner', status: 'success', content: fulfillment_message -%}
          {%- endif -%}

Converting it to Liquid tag is simple, but once this line is hit:

<div class="banner__text-with-button">
                  {{- fulfillment_message -}}
                  {%- render 'button', href: fulfillment.tracking_url, external: true, content: button_content, size: 'sm' -%}
                </div>

This becomes something like this:

echo '<div class="banner__text-with-button">'
echo fulfillment_message
echo '</div>'

The issue here is that we loose all the color syntaxing and validation of the IDE.

I think that we should have a new option for the Liquid check to does not count a block as soon as it contains a HTML code. In this case, the whole if condition should count as "0" line of Liquid if this option would be enabled.

Of course, a better solution would be to improve the Liquid tag to allow outputting HTML inside.

@bakura10 bakura10 added the bug Something isn't working label Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant