Comment Module Tags

A basic example of the Comment tag:

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

{comment}

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

{/exp:comment:entries}

Parameters

limit=

limit="30"

Allows you to limit the number of comments.

sort=

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.

weblog=

weblog="which"

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:

weblog="weblog1|weblog2|weblog3"

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.

Variables

aol_im

{aol_im}

The author's AOL IM account name

comment

{comment}

The body of the comment

entry_id

{entry_id}

The ID number of the entry

icq

{icq}

The author's ICQ IM user identification number

interests

{interests}

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

ip_address

{ip_address}

The IP address of the commenter

location

{location}

The author's location as entered in their profile

msn_im

{msn_im}

The author's MSN IM account name

occupation

{occupation}

The author's occupation as entered in their profile

name

{name}

Name of the author

permalink

{permalink}

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

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

switch=

{switch="option_one|option_two}

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:

{exp:comment:entries}
<div class="{switch="one|two"}">
<h1>{name}</h1>
{comment}
</div>
{/exp:comment:entries}

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_or_email

{url_or_email}

URL if it exists, otherwise the email address

url_or_email_as_author

{url_or_email_as_author}

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

url_or_email_as_link

{url_or_email_as_link}

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

weblog_id

{weblog_id}

The ID number of the actual weblog

yahoo_im

{yahoo_im}

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:

{age}
{gender}
{zodiac}
etc..

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

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

The date of the comment.

edit_date

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

The date on which the comment was edited.

Conditionals

Conditionals work in comments:

{if name=="bozo"}

You've got a big nose!

{/if}

Comment Submission Form

{exp:comment:form}

{/exp:comment: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>

{/if}

<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" />

{/exp:comment:form}

Notes:
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.

Previewing

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:

{exp:comment:preview}

{comment}

{/exp:comment: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.