PAD Showcase
All tags/Time ago

A comment thread

Each comment says how long ago it was posted; hover a time for the full date, and the datetime attribute carries the exact moment.

1 The data timeago/comments.php php
<?php

  // A thread whose comments were posted some time before now.

  $comments = [];

  foreach ( [ [ 'Maya',   '#2a78d6', '-4 months',   'Is there a way to export the report as a spreadsheet?' ],
              [ 'Jonas',  '#1baf7a', '-3 weeks',    'The CSV answer of the same page does exactly that.' ],
              [ 'Priya',  '#eb6834', '-1 day',      'Tried it today - one line in the page and it works.' ],
              [ 'Tomás',  '#7c5cff', '-2 hours',    'Can the columns be chosen?' ],
              [ 'Maya',   '#2a78d6', '-5 minutes',  'Yes: list them in the page, in the order you want.' ],
              [ 'Ken',    '#e34948', '-3 seconds',  'Thanks, everyone!' ] ] as list ( $name, $color, $when, $text ) )
    $comments [] = [ 'name' => $name, 'color' => $color, 'posted' => padNow ()->modify ( $when )->format ( 'Y-m-d H:i:s' ), 'text' => $text ];

?>
2 The template timeago/comments.pad pad
<ol style="list-style:none;margin:0;padding:0;max-width:32em;display:grid;gap:16px">
  {comments}
  <li style="display:grid;grid-template-columns:40px 1fr;gap:12px">
    <span aria-hidden="true" style="width:40px;height:40px;border-radius:50%;display:grid;place-items:center;font-weight:700;color:#fff;background:{$color}">{$name | left(1)}</span>
    <div>
      <strong>{$name}</strong> <small style="opacity:.65">· {timeago $posted}</small>
      <p style="margin:4px 0 0;line-height:1.5">{$text}</p>
    </div>
  </li>
  {/comments}
</ol>
3 The result rendered on the server
  1. Maya ·

    Is there a way to export the report as a spreadsheet?

  2. Jonas ·

    The CSV answer of the same page does exactly that.

  3. Priya ·

    Tried it today - one line in the page and it works.

  4. Tomás ·

    Can the columns be chosen?

  5. Maya ·

    Yes: list them in the page, in the order you want.

  6. Ken ·

    Thanks, everyone!