SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2011
    Location
    San Diego
    Posts
    111
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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:

    PHP Code:
    <p>{$child->body2|nl2br}</p
    The answer might come from one of these,

    Parent ID
    PHP Code:
    {$item->id
    Time Ago in Smarty:
    PHP Code:
    {$item->timeago
    Thank you

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,151
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    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.
    The only code I hate more than my own is everyone else's.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •