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:
The `if_comments` does a thing if one or more comments have been submitted and moderated. It’s typically used like this:
<txp:if_comments> <span>some comments have been submitted</span> <txp:else /> <span>zero comments have been submitted</span> </txp:if_comments>
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:
<txp:if_comments> <span>[Comments: <txp:comments_count />]</span> <txp:else /> <p>[Comments: none yet - be the first]</p> </txp:if_comments>
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`:
<txp:if_comments_allowed> <span>Comments are <strong>open</strong>.</span> <txp:else /> <span>Comments are <strong>closed</strong>.</span> </txp:if_comments_allowed>
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:
<txp:if_comments_disallowed> <span>Comments are <strong>closed</strong>.</span> <txp:else /> <span>Comments are <strong>open</strong>.</span> </txp:if_comments_disallowed>
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:
<txp:if_comments_error> <span>There was a problem with your comment</span> </txp:if_comments_error>
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.