article

You can use the article variable in the following templates: article.liquid.

The liquid variable article has the following attributes:

article.author
{% for article in blog.articles %}
  <p>{{ article.author }}</p>
{% endfor %}

Returns the name of the author of an article.

article.comments
{% for comment in article.comments %}
<div>
  {{ comment.content }}
</div>
{% endfor %}

Returns all of the published comments for this article if comments are enabled for the blog that the article belongs to. Only the most recent 25 comments will be shown. Use the paginate function to return less.

If comments are not enabled, this will return an empty array.

To view comment attributes, click here.

article.comments_count
{% if article.comments_count > 0 %}
  <p>You have more than one comment!</p>
{% endif %}

Returns the number of published comments for an article.

article.comments_enabled?
{% if article.comments_enabled? %}
  <p>Comments are enabled on this blog!</p>
{% endif %}

Returns "true" if comments are enabled for this blog, otherwise it returns "false."

article.comment_post_url
{% if blog.comments_enabled? %}
  {{ article.comment_post_url }}
{% endif %}

Returns the relative URL where POST requests should be sent to create a new comment.

article.content
<div>
  <p>{{ article.content }}</p>
</div>  

Returns the content of an article.

article.created_at
<p> posted {{ article.created_at | date: "%Y %h" }} by {{ article.author }}</p>

Returns the date/time when an article was created. Use the date filter to change the date/time fields that are returned.

article.excerpt
{% for article in blog.articles %}
  {% if article.excerpt == blank %}
    This article has no excerpt. Instead, include 30 words from the content.
    {{ article.content | strip_html | truncate: 30}}
  {% else %}
    {{ article.excerpt }}
  {% endif %}
{% endfor %}

Returns the excerpt of an article (if the article has an excerpt).

article.excerpt_or_content
{% for article in blog.articles %}
  {{ article.excerpt_or_content }}
{% endfor %}

Returns the excerpt of an article (if an article has an excerpt) or the first few words of the article's content.

article.id
{% for article in blog.articles %}
  <li id="{{ article.id }}">
    {{ article.content }}
  </li>
{% endfor %}

Returns the id of an article.

article.moderated?
{% for article in blog.articles %}
  {{ article.moderated? }}
{% endfor %}

Returns "true" if the blog is set to moderate comments, otherwise it returns "false."

article.published_at
{{ article.published_at | date: "%B %d, %Y" }}

Returns the date/time when an article was published. Use one of the date filters to change the date/time fields that are returned.

article.tags
{% for tag in article.tags %}
{{ tag | link_to_tag: tag }}
{% endfor %}

Returns all the tags for an article.

article.title
<h1>{{ article.title }}</h1>

Returns the title of an article.

article.url
<p>Posted by {{ article.author }} on {{ article.created_at | date: "%B %d, %Y" }} <span>(<a href="{{ article.url }}{% if blog.comments_enabled? %}#comments{% endif %}">{{ article.comments_count }} {{ article.comments_count }}</a>)</span></p>

Returns the relative URL where the blog can be found. This will append the #article-id so that the page should automatically scroll to the corresponding article.

article.user.account_owner
{% for article in blog.articles %}
  {{ article.user.account_owner }}
{% endfor %}

Returns "true" if the author of the article is the account owner, or "false" if the author is not the account owner.

article.user.bio
{% for article in blog.articles %}
  {{ article.user.bio }}
{% endfor %}

Returns the bio of the author of an article.

article.user.email
{% for article in blog.articles %}
  {{ article.user.email }}
{% endfor %}

Returns the email of the author of an article.

article.user.first_name
{% for article in blog.articles %}
  {{ article.user.first_name }}
{% endfor %}

Returns the first name of the author of an article.

article.user.homepage
{% for article in blog.articles %}
  {{ article.user.homepage }}
{% endfor %}

Returns the web address of the author of an article.

article.user.name
{% for article in blog.articles %}
  {{ article.user.name}}
{% endfor %}

Returns the author of an article. Same as article.author.

article.user.last_name
{% for article in blog.articles %}
  {{ article.user.last_name }}
{% endfor %}

Returns the last name of the author of an article.


Comment

The liquid variable comment is only available after a comment has been posted.

The liquid variable comment has the following attributes:

comment.author
{% for comment in article.comments %}
  {{ comment.author }}
{% endfor %}

Returns the author of a comment.

comment.content
{% for comment in article.comments %}
  {{ comment.content }}
{% endfor %}

Returns the content of a comment.

comment.created_at
{% for comment in article.comments %}
  Created on:{{ comment.created_at | date: "%B %d, %Y" }}
{% endfor %}

Returns the date/time when the comment was created. Use one of the date filters to change the date/time fields returned.

comment.email
{% for comment in article.comments %}
  <p>{{ comment.email }}</p>
{% endfor %}

Returns the e-mail address of the author of the comment.

comment.id
{% for comment in article.comments %}
  <li id="{{ comment.id }}" class="comment{% unless number_of_comments > article.comments_count %}{% if forloop.first %} first{% endif %}{% endunless %}{% if forloop.last %} last {% endif %}">
    {{ comment.content }}
  </li>
{% endfor %}

Returns the id of the comment.

comment.status
<div class="comments">
{% for comment in article.comments reversed %}
  {{ comment.status }
{% endfor %}
</div>

Returns the status of the comment, either: 'unapproved,' 'published,' 'removed,' or 'spam.'

comment.url
<a href="{{ comment.url }}">{{ comment.created_at | date: "%B, %d, %Y" }}</a>

Returns the relative URL where the article can be found. This will append the comment's id as an anchor so that the page should automatically scroll to the corresponding comment.


Form tags

By default, the article.liquid template uses the form tag which is used to check if a comment has been posted successfully, or if there are any input errors. In the article.liquid template, you have access to the following form tags:

form.author
{% form article %}
<p>
<label for="comment-author">Name</label>
<input required{% if form.errors contains "author" %} class="error"{% endif %} type="text" name="comment[author]" placeholder="Your name" id="comment-author" value="{{ form.author }}" />
</p>

Returns the author of the last comment posted (only if there was an error).

form.body
{% form article %}
<p>
<label for="comment-body">Message</label>
<textarea required{% if form.errors contains "body" %} class="error"{% endif %} name="comment[body]" id="comment-body">{{ form.body }}</textarea>
</p>

Returns the body of the comment last posted (only if there was an error).

form.email
{% form article %}
<p>
<label for="comment-email">Email</label>
<input required{% if form.errors contains "email" %} class="error"{% endif %} type="email" name="comment[email]" placeholder="your@email.com" id="comment-email" value="{{ form.email }}" />
</p>

Returns the email of the last comment posted (only if there was an error).

form.errors
{% if form.errors %}
  Your comment has not been posted. Make sure you have filled out all the fields correctly.
{% endif %}

Returns empty if a comment was submitted succesfully or returns one or more of the fields that were submitted incorrectly.

form.posted_successfully
{% if form.posted_successfully? %}
  Your comment has been submitted.
{% endif %}

Returns "true" if a comment by the user was submitted successfully, or "false" if the form has errors.

Ready to put what you've learned into action?

Build an online store with Shopify Try it Free

Experience the future of retail now

Shopify Point of Sale Try it Free