Sorting in Smarty

I’m using a site that was built using Smarty. I didn’t type the code myself and I’m not very familiar with it so I’m hoping someone could help me out here.

The site has posts (confessions) and people are able to leave comments, but the comments sometimes appear out of order. I would like to have them sorted in ascending order either by their child id or by date.

Here’s what I want to fix:

<p>{$child->body2|nl2br}</p>

The answer might come from one of these,

Parent ID

{$item->id}

Time Ago in Smarty:

{$item->timeago}

Thank you

Well if those comments are coming from the database you really should consider adding sorting to the query that generates comments. Sorting the comments in a smarty template is dirty and introduces logic that really has no place at the presentation layer. The sorting should either be done outside the smarty template or ideally within the query itself to generate the comments.