Distinguishing preview comment from other comments

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
eikimart
Regular
Posts: 5
Joined: Mon Mar 28, 2011 8:57 pm

Distinguishing preview comment from other comments

Post by eikimart »

I'd like to visual mark the user's preview comment so that it appears differently from the rest of the comment history. But it seems that serendipity_smarty_printComments just appends the preview onto the end of the rest of the comments with no hook my template could use to apply a different class or whatever.

Is there another way to go about this? One way to get what I want is to have a conditional in comments.tpl, similar to that used for distinguishing author comments:
{if $comment.author == $entry.author}<div class="mycomment">{else}<div class="comment">{/if}

But I might also want to change the location of the preview comments in the document flow, something roughly like this (in entries.tpl):

<h2>Comments:</h2>
{serendipity_printCommentsNoPreview entry=$entry.id mode=$entry.viewmode}
<h2>Your comment (preview):</h2>
{serendipity_printPreviewComment entry=$entry.id mode=$entry.viewmode}

I could write this, but I obviously don't want to fork s9y. Is there another way to iterate over the comments? Should I do this in a plugin instead? Thanks!
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Distinguishing preview comment from other comments

Post by yellowled »

eikimart wrote:I'd like to visual mark the user's preview comment so that it appears differently from the rest of the comment history.
Theoretically, i.e. untested, this should be doable with CSS only. Assuming default/comments.tpl, any comment gets assigned an id:

Code: Select all

<div id="serendipity_comment_{$comment.id}" [...]
For the preview, this {$comment.id} seems to be empty, so the id should be #serendipity_comment_. You could use that for css styling. However, might or might not work in any given template with a unique comments.tpl.

YL
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Distinguishing preview comment from other comments

Post by garvinhicking »

Hi!

Also, you wouldn't necessarily fork core features; you could create your custom function in the template's config.inc.php file, and since the user's comment is stored in $serendipity['POST'] you could access it to be printed "outside" of the usual flow (in addition to the normal s9y flow, though - if needed you could work around that though with some more code).

The comment addition BTW happens in include/functions_smarty.inc.php, serendipity_smarty_printComments - it just appends $comments[] with the POSTed data.

However, that what yellowled mentions should work as well, and you could even use jQuery (if you want) to reposition the element within the DOM - that would be the less complex, but maybe easiest approach.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Distinguishing preview comment from other comments

Post by yellowled »

garvinhicking wrote:However, that what yellowled mentions should work as well, and you could even use jQuery (if you want) to reposition the element within the DOM - that would be the less complex, but maybe easiest approach.
That's an awesome idea given that a lot of people complain about the fact that S9y doesn't automagically scroll to the preview. We should definitely keep that in mind for future versions. :)

YL
Post Reply