Shopify / liquid

Liquid markup language. Safe, customer facing template language for flexible web apps.
https://shopify.github.io/liquid/
MIT License
11.11k stars 1.39k forks source link

Snippet generates extra unnecessary comments #1706

Open its-anas opened 1 year ago

its-anas commented 1 year ago

1) I want to use a snippet that converts hex to rgba:

<!-- color_to_rgba.liquid -->
{%- 
  liquid
  assign rgb = color | color_to_rgb
  assign tail = opacity | prepend: ', ' | append: ')' 
-%}
{{ rgb | replace: 'rgb', 'rgba' | replace: ')', tail }}

2) And it should returns the output so i can use it inside page CSS:

<!-- page.liquid -->
<style>
    --converted-rgba-color: {{% render 'color_to_rgba', color: '#000', opacity: '0.5' %}}
</style>

3) But instead of getting only the output, there is extra 2 wrapping comments i'm unable to get rid of:

<style>
    --converted-rgba-color: <!-- BEGIN app snippet: test -->rgba(0, 0, 0, 0.5)<!-- END app snippet -->
</style>
thosakwe commented 8 months ago

Can these comments be removed?

It makes it impossible to create a snippet that returns JavaScript code.

At this time, we have to treat all snippets as HTML output.

ShlomiAmichay commented 3 months ago

Had the same issue and reached here, if anyone encounters the same issue, I've used the strip_html filter to remove those comments

{% capture content %}{% render 'some-snippet'%}{% endcapture %}
<style>
    {{ content | strip_html }}
</style>