Home > Shopify Development > Comment Syntax How to Comment Out Liquid Code

How to comment out liquid code in Shopify

Sam Nguyen
Sam Updated: June 30, 2024

Share:

Drive 20-40% of your revenue with Avada
avada email marketing

Maintaining clean and well-documented code is essential for efficient Shopify theme development.  Commenting out Liquid code provides a powerful way to temporarily disable sections, add explanations, or troubleshoot issues without impacting your storefront.  Discover how to effectively utilize comment tags and other techniques to enhance your Shopify theme's clarity and maintainability. 

Requirements of commenting out liquid code in Shopify

1. Using Comment Tags

This is the primary method for commenting out blocks of Liquid code.

Syntax:


{% comment %} (Start of the comment block)
The code you want to comment out goes here
{% endcomment %} (End of the comment block)

Example:

Code snippet


{% comment %}
  This is a multi-line comment.
  Any Liquid code or text within these tags will be ignored.
{% endcomment %}

2. Using Inline Comments with Liquid 5.4+

Introduced in Liquid version 5.4, this allows for single-line comments within Liquid code.

Syntax:


{% # This is an inline comment %}

Example:

Code snippet


{% if product.available %} 
<p>In stock</p> {% # Display "In stock" if the product is available %} 
{% endif %}

3. Using Raw Tags for Mixed Content

If you need to comment out Liquid code mixed with HTML or other content, use raw tags to prevent rendering.

Syntax:


The mixed content you want to comment out goes here

Example:

Code snippet


<h1>{{ product.title }}</h1> {% # This Liquid code won't be processed %} 

Conclusion

In conclusion, comment tags help you to increase your website interface with customers. Visitors can leave their comments about your products or ask for further information, hence you would instantly answer these comments. We hope that the tutorial is helpful and if you have any difficulties, let’s us know and we will support you.

FAQs

Use the comment and endcomment tag pair to enclose the code you want to temporarily disable.

If you're using Liquid version 5.4 or later, you can use inline comments with.

tags to prevent both Liquid and HTML from being rendered.

Yes, comments remain in the source code, even though they're not rendered on the storefront. This is helpful for documentation and collaboration.

While comments are helpful, excessive use can make your code harder to read and maintain. Strive for a balance between commenting and clean code.

Sam Nguyen is the CEO and founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore. He is an expert on the Shopify e-commerce platform for online stores and retail point-of-sale systems. Sam loves talking about e-commerce and he aims to help over a million online businesses grow and thrive.

Stay in the know

Get special offers on the latest news from AVADA.