Template tags

Template tags are a bit of an oddments drawer you can use to do a variety of things within your code. They can do things like prevent comments from being output, display raw Liquid code, and sometimes control output of template elements. Let’s take a look at the comment tag, as you’ll be reading and (and hopefully entering) comments in your code!

Code (key and tag){% comment %} 
I wrote the code this way for a good reason!
{% endcomment %}
Output 

The output is… nothing! That means your comments are visible to someone reading the Liquid code, but your customers won’t see a thing in the email. 

Practice problem: template tags

See if you can identify the correct way to use the comment tag.

Add the comment “Insert new product information here” to your code.

Select the right Liquid code from the options below:

a. {% comment %} 

Insert new product information here

b.{{ comment }}

Insert new product information here

{{ endcomment }}

c.{% comment %} 

Insert new product information here

{% endcomment %}

d. Insert new product information here

The correct answer is C!

Let’s run the code.

Code (key and tag){% comment %} 
Insert new product information here
{% endcomment %}
Output 

Why don’t the other options work?

a. Missing the closing section of the tag.

b. Uses double curly braces instead of paired curly brace and percentage signs to enclose the tag.

d. Tag is missing.