Monday 24 October 2005 by sencer

Now you can finally put the preview where you think it belongs and change and customize how it looks to your desire. So what does it practically gain you? For example now you can truly have a 2-column layout with the article on one side and the comments, comments-form and comments-preview on the other side. Up to now, the preview would always appear hardcoded in front of the article. Of course everything is backwards-compatible, so if you leave your templates as they are the preview will still be where it used to be.

Here is a code example:

<txp:if_comments_preview>
<div id="cpreview" style="background-color:#FF0"><b>Hello, the following is only a preview. Please re-read your comment for clarity and hit submit once you approve of it.</b>
<txp:comments_preview form="my_preview" />
<txp:comments_form />
</div>
</txp:if_comments_preview>

You can see that we enclosed it in the new preview-conditionals. First we add an anchor (cpreview) so that the browser can scroll to the correcct spot on the page during preview. We also highlight the enclosing div with a yellow background to inform users that here is something to pay attention to. Then there’s a textual message to inform the user this is only a preview. Next, txp:comments_preview is called which renders the comment with a form called my_preview (which looks just like a regular display form for comments like the built-in “comments” which is used by default). Next is the comments_form which has to be called with preview="1", so it will be shown during the preview. (update 30. Oct 2006: This is the default behaviour as of 4.0.4, therefor that attribute does not exist anymore. Take a look at this FAQ for the current state of comment-previews.)

The key element in all this is the <txp:comments_preview /> tag. If that is encountered anywhere on the page, the old behaviour of prepending comments is automatically turned off. This also means you can use the conditional independant of customized previews, for example to simply show a message at the top of your page.

Sidenote: While we are talking about comments, the comments_invite tag has also seen a bit of a renovation. It has three new attributes, which you can see here:

<comments_invite showcount="0" textonly="1" showalways="1" />

showcount will show or hide the number of comments next to the invite. textonly will return the invite-text as just text, without a link. And finally if showalways is set to 1, the invite will also display on individual article pages (which it doesn’t by default, for historical reasons).