Textpattern conditional comment tags


Textpattern CMS comment tags include a few conditionals. That is to say, if a thing evaluates to true, do something, otherwise do something else. I’m simplifying it so you can get your head around it, but here are the tags:

  • if_comments
  • if_comments_allowed
  • if_comments_disallowed
  • if_comments_error
  • if_comments_preview

The `if_comments` does a thing if one or more comments have been submitted and moderated. It’s typically used like this:

<span>some comments have been submitted</span>
<txp:else />
<span>zero comments have been submitted</span>

The container stuff is not limited to `<span>`, I’m just using that as an example. You could extend this a bit and do something more useful, like this:

<span>[Comments: <txp:comments_count />]</span>
<txp:else />
<p>[Comments: none yet - be the first]</p>

See that call to action? It’s all about calls to action.

Now, a confession from me. The next two tags are, in my humble opinion, a mis-step by the developer who implemented them. Take the following example of `if_comments_allowed`:

<span>Comments are <strong>open</strong>.</span>
<txp:else />
<span>Comments are <strong>closed</strong>.</span>

See how that works? If allowed, then tell folks comments are open, and otherwise, tell them they’re closed. Comments can be open or closed. That’s it. Now, consider the `if_comments_disallowed` tag. That’s just turning the above code on its head:

<span>Comments are <strong>closed</strong>.</span>
<txp:else />
<span>Comments are <strong>open</strong>.</span>

Huh. The whole point of a conditional is that only one tag is required. If This Is A Thing, Do That, Otherwise Do Something Else. When I become universal overlord of the world I will make it a point to deprecate `if_comments_disallowed`.

For a CMS built on a foundation of speed and low resources, this is one of the things someone should’ve spotted and removed before it hit production. Now, of course, it’s too late to deprecate it, regardless of whether or not I reach global overlord status in my life journey.

I digress. Let’s move on.

The `if_comments_error` is more useful – that checks to see if the submitter has made a mistake and alerts them to it with another call to action. You see – I told you it’s all about calls to action. I wasn’t kidding. Like this:

<span>There was a problem with your comment</span>

You could factor in an `else` tag if you want to, but if all goes to plan and the comment is successfully left the submitter is shown another message telling them of this

Lastly, I explained about the comment preview requirement on Textpattern. It’s something that’s been the case for many years, and although I have only anecdotal evidence to support this statement – it reduces comment spam enormously – there’s never really been any real pressure to change it. As to how users of Textpattern sites like this, I don’t know – what do you think of it? Let me know.

See? Call to action.

Next time: more reading on comment tags, for the super-studious among you.

Looking for quality Textpattern Hosting? Look no further than Arvixe Web Hosting and use coupon TEXTPATTERN for 20% off your first invoice!

Tags: , , , , , , , , , , , , | Posted under Textpattern | RSS 2.0

Author Spotlight

Pete Cooper

Pete Cooper has been using Textpattern since 2005. Textpattern is his preferred CMS weapon of choice. Its logical and flexible approach to content management makes Pete happy, as does its lightweight core and helpful user community. Pete's website - petecooper.org - runs on top of Textpattern and chronicles his day-to-day experiences from his home near the Atlantic in north Cornwall, United Kingdom.

Leave a Reply

Your email address will not be published. Required fields are marked *