Skip to content

Request for suggestions: Liquid comments #1393

Closed
@tobi

Description

@tobi

Right now comments in liquid are implemented through the {% comment %} tag. Basically a block that doesn't do anything.

This has always been clunky and I think we should introduce syntax for this.

This is especially true because of the new liquid block tag. Consider that this is the only way to do inline comments right now:

{% liquid
comment Is the feature_image set? 
endcomment

if product.featured_image
  echo product.featured_image | img_tag
else
  echo 'product-1' 
endif 
%}

Which... is bad.

My current thinking is that we should double down on our ruby heritage and designate # as the comment character. Alternatives here would be c style // or lua style --

This would transform the above to

{% liquid
# Is the feature_image set? 
if product.featured_image
  echo product.featured_image | img_tag
else
  echo 'product-1' 
endif 
%}

Additionally we could introduce a new inline token for comments:
Single line comment {# comment #} and multiline comments would be both supported

{# 
  First line 
  Second line
#}

The downside of this syntax is that it may cause collisions in existing liquid code. We can (but haven't) check the Shopify databases for how common this might be.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions