Comment Module Tags

A basic example of the Comment tag:

{exp:comment:entries sort="asc" limit="20"}


<p>By {name} on {comment_date format="%Y %m %d"}</p>





Allows you to limit the number of comments.


sort="asc" or sort="desc"

The sort order can be "asc" (ascending order or "oldest item first") or "desc" (descending order or "newest item first"). If you do not use a sort order the default is desc.



From which weblog to show the comments (will show comments from any weblog if no weblog is specified). Additionally, you can use the pipe character to separate multiple weblogs:


Or you can add the word "not" (with a space after it) to exclude weblogs:

weblog="not weblog1|weblog2|weblog3"

The weblog= parameter can have some security implications. If you do not use this parameter then it is possible that people could see comments for a weblog entry to which they otherwise would not have access. If you use multiple weblogs and want to make sure only certain people can see certain content, then you're encouraged to make use of this parameter.




The author's AOL IM account name



The body of the comment



The ID number of the entry



The author's ICQ IM user identification number



The author's "interests" as entered in their profile



The IP address of the commenter



The author's location as entered in their profile



The author's MSN IM account name



The author's occupation as entered in their profile



Name of the author



The URL to the actual comment with anchor. Put this variable in a link:

<a href="{permalink}">permanent link</a>



This variable permits you to alternate between any two values as the entries are displayed. The first entry will use "option_one", the second will use "option_two", the third "option_one", and so on.

The most straightforward use for this would be to alternate colors. It could be used like so:

<div class="{switch="one|two"}">

The entries would then alternate between <div class="one"> and <div class="two">.

Multiple instances of the {switch=} tag may be used and the system will intelligently keep track of each one.



URL if it exists, otherwise the email address



Hyperlink or email link as author screen_name (or username if they haven't specified a screen name)



Same as above only it will display the URL or email address as a link



The ID number of the actual weblog



The author's Yahoo IM account name

Custom Member Fields

All custom member profile fields can be accessed using the "short name" of the field:


These are totally dynamic in that any profile field you create for your members will automatically be available by its "short name" as a variable.

Single Variable Dates

Several date variables are available for use. As with other date variables, these require the "format" parameter in order to define how the date should be displayed. SSee the date variable formatting page for more information.


{comment_date format="%Y %m %d"}

The date of the comment.


{edit_date format="%Y %m %d"}

The date on which the comment was edited.


Conditionals work in comments:

{if name=="bozo"}

You've got a big nose!


Comment Submission Form



There is one required parameter in the comment form but only if you want to use the preview feature:

{exp:comment:form preview="weblog/preview"}

The "preview" parameter specifies the template group/template in which the preview will be shown. More on previewing later.

The comment form is created pretty much like a normal form, only you don't specify the opening and closing form tags. There are a few variables that are required in order to enable people's personal information (name, email, url, etc.) to appear in the form. Here's how the comment form is typically created:

{exp:comment:form preview="weblog/preview"}

{if logged_out}

<p>Name: <input type="text" name="name" value="{name}" size="50" /></p>

<p>Email: <input type="text" name="email" value="{email}" size="50" /></p>

<p>Location: <input type="text" name="location" value="{location}" size="50" /></p>

<p>URL: <input type="text" name="url" value="{url}" size="50" /></p>


<p><textarea name="comment" cols="70" rows="10">{comment}</textarea></p>

<p><input type="checkbox" name="save_info" value="yes" {save_info} /> Remember my personal information</p>

<p><input type="checkbox" name="notify_me" value="yes" {notify_me} /> Notify me of follow-up comments?</p>

<input type="submit" name="submit" value="Submit" />
<input type="submit" name="preview" value="Preview" />


The conditional variable {if not_logged_in} allows the system to show the short form (textarea only) if the user is a logged in member. We recommend you use the form this way because if a member is logged in, their personal data is fetched automatically.

Notice the variables in the "value" form fields? These allow us to show the user's information in the form automatically if they click the "remember personal info" option.


To preview a comment requires that you create a specific template for it. This template will contain at minimum two tags. The first is the tag that shows the preview:




The second is the comment form tag from earlier. This allows the comment to be displayed as well as the form containing the info so it can be previewed again or submitted.