if is a Liquid block which encapsulates the comment form, so it can be displayed correctly in all themes.
Syntax
{% commentform %}
Your name: {{ commentform.author }}
Your e-mail: {{ commentform.email }}
Your website: {{ commentform.website }}
Your comment:
{{ commentform.text }}
{{ commentform.submit }}
{% endcommentform %}
commentform is used to display the comment form correctly, including the input fields in it. How the form is displayed depends on, first of all, whether the form was already submitted but errors were found or not, and secondly, on whether the user is logged in or not.
To use this block, you need to encapsulate the whole form in the tags {% commentform %} and {% endcommentform %}. These tags will automatically insert the <form> and </form> tags, as well as some other hidden input fields containing the entry id and slug.
In the form, you'll have some variables available to deal with the comment forms correctly. First of all, these are the HTML tags for all form fields:
- {{ commentform.author }}
- Containing the <input> tag for the comment author's name.
- {{ commentform.email }}
- Containing the <input> tag for the comment author's e-mail address.
- {{ commentform.website }}
- Containing the <input> tag for the comment author's website.
- {{ commentform.text }}
- Containing the <textarea> tag for the comment text.
- {{ commentform.submit }}
- Containing the <input> tag for the submit button.
The contents of these tags change depending on whether the user is logged in (so his credentials are already known and the author, email and website input tags can be of the type "hidden"), and whether the comment has already been submitted but must be edited because errors occured (so we must display the previous input of the fields).
You can get to know these criteria using the following tags (which are always true or false):
- {{ commentform.complete }}
- Whether a complete form is displayed (user is NOT logged in) or not (user is logged in).
- {{ commentform.submitted }}
- Whether the form was already submitted or not.
If you want to know exactly what the output of these tags can be, take a look at the source code in the file lib/chameleon/liquid/comment_form.rb.
The code to generate this block is based on Mephisto's CommentForm.
Examples
{% commentform %}<!-- Start comment form. -->
<h3><a name="respond">Leave a comment</a></h3>
<!-- Show possible errors. -->
{{ comment.errors }}
{% if user %}<!-- The user is logged in. -->
<p>Logged in as <a href="{{ user | url_for_editing_user }}" title="View profile">{{ user.nickname }}</a>.
<a href="{{ user | url_for_log_out }}" title="Log out of this account">Log out</a>.</p>
{% endif %}
{% if commentform.complete == false %}<!-- The user is logged in: do not ask for name, ... -->
{{ commentform.author }}
{{ commentform.email }}
{{ commentform.website }}
{% else %}<!-- The user is not logged in, or errors occured: display all fields. -->
<ul>
<li><label for="comment_author">Name</label> {{ commentform.author }}</li>
<li><label for="comment_email">Mail</label> {{ commentform.email }}</li>
<li><label for="comment_website">Website</label> {{ commentform.website }}</li>
</ul>
{% endif %}
<p><label class="text" for="comment_text">Comment:</label></p>
{{ commentform.text }}
<p>You can use <a href="http://textism.com/tools/textile/">Textile</a> to format your comments.</p>
{{ commentform.submit }}
{% endcommentform %}





