Beginner Question about Nested Comments

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
drx
Regular
Posts: 17
Joined: Fri May 26, 2006 3:04 pm
Contact:

Beginner Question about Nested Comments

Post by drx »

Hi, i would like to know if it is possible to change the display of nested comments into a real nested HTML list. You know, something like

Code: Select all

<ul>
 <li>#1
   <ul>
    <li>#1.1</li>
   </ul>
 </li>
 <li>#2</li>
</ul>
So the markup would actually represent the nesting structure.

I didn't really get if the markup produced by all the sites using s9y is a built-in freature or if it can be changed in any way ...

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

Re: Beginner Question about Nested Comments

Post by garvinhicking »

Hi!

Since nesting elements like this imposes many problems in browsers (especially concerning padding/margins and wrapping) we went the way to "walk" a nested array and build it into a sequential array with numbers indicating the nesting "depth" level.

This can then be edited in the "comments.tpl" template file. I think you could be able to use that sequential order to build the nested order again using smarty markup, but that's certainly some work to do.

The bottom line is, I wouldn't recommend it, just because of the sake of nested items. The nesting can properly be indicated with CSS, and with much more control than the other way, so I don't see a pressing reason why to take on that building. Recursion is certainly slower in this case than just indexed sequences...

HTH,
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/
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

Check out the comments.tpl in my Dusk theme. It isn't exactly what you want but might give you some inspiration.
drx
Regular
Posts: 17
Joined: Fri May 26, 2006 3:04 pm
Contact:

Re: Beginner Question about Nested Comments

Post by drx »

Hi, thanks for your answer!
This can then be edited in the "comments.tpl" template file. I think you could be able to use that sequential order to build the nested order again using smarty markup, but that's certainly some work to do.
So it is possible to access this depth level somehow?

Some time ago i used this logic to create a nested comment list with the same data available:

Code: Select all

$Level = 0;
foreach(array_keys($Entries) as $Key)
	{
	if($Level != $Entries[$Key]['Level'])
		{
		if($Level>$Entries[$Key]['Level'])
			{
			while($Level > $Entries[$Key]['Level'])
				{
				echo "</li>\n</ul>\n";
				$Level--;
				echo "</li>\n";
				}
			}
		else
			{
			while($Level < $Entries[$Key]['Level'])
				{
				echo "<ul>\n";
				$Level++;
				}
			}
		}
	else
		{
		echo "</li>\n";
		}

        // actual comment goes here
 
    }

	while($Level > 0)
		{
		echo "</li>\n</ul>\n";
		$Level--;
		}
The bottom line is, I wouldn't recommend it, just because of the sake of nested items. The nesting can properly be indicated with CSS, and with much more control than the other way, so I don't see a pressing reason why to take on that building. Recursion is certainly slower in this case than just indexed sequences...
Recursion wouldn't be needed, if i understand correctly what you said about the flat array.

I think the argument about problems with display are not really valid, with some more lines of CSS all the issues can be fixed and the HTML would actually have a meaning instead of being just a lot of DIVs. It would also work without any stylesheets at all. Also through proper nesting Javascripts could be introduced to display/hide subtrees of a discussion.

It just looks extremely weird to have the software generate a "1.1" kind of numbering when this is one of the few things that HTML can actually do by itself through markup! :)

I recommend using "correct" nesting by default. I was happy to find a blog software where nested comments are a core feature because i want something to enable discussions; i really think all these flat comments all over the web are a huge step backwards.

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

Re: Beginner Question about Nested Comments

Post by garvinhicking »

Hi!

Yes, the depth can be acceessed in comments.tpl through smarty via:

Code: Select all

{$comment.depth}
About the nesting: My experience from nested <ul>s in the past was, that it created more trouble than it solved. If you get it all properly working, all the better. Maybe you could show the final result to us, so that we could check it in a few browsers and see about using that in the future for the default?

HTH,
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/
drx
Regular
Posts: 17
Joined: Fri May 26, 2006 3:04 pm
Contact:

years later ...

Post by drx »

... i finally made a template for nested comments. It works well, only based on smarty and the $comment.depth variable. Also, i used jQuery to let the comment form appear right under the comment you want to reply to, but it still works without javascript turned on in the classic s9y way.

Is there a place to show this code around?

(I helped coding some discussion forums before that used nested lists and it all worked out, even in Netscape 4, with hundreds of comments.)

bests, drx
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers »

drx - post a download link to your code so we can check it out if you can.
=Don=
drx
Regular
Posts: 17
Joined: Fri May 26, 2006 3:04 pm
Contact:

Test it here ...

Post by drx »

Hello,

the theme's code is here:
http://nm.merz-akademie.de/~dragan.espe ... ravers.zip
It works mostly for my needs but is not ready for a proper release.

You can try the nested comments on this post if you like:
http://nm.merz-akademie.de/~dragan.espe ... stars.html
It's localized in German, click "Antwort" to post a reply or fill the form.

Tested in Firefox 2.x, IE 6+, Opera 9.2+, Konqueror 3.5.7 ... my experience is that if it works in Konqueror, it works everywhere ;)

Bests,
drx
mark007
Posts: 2
Joined: Fri Sep 07, 2007 11:23 am

Post by mark007 »

Thanks a lot
Post Reply