"List" macro in templates

Bug #240432 reported by Jeroen T. Vermeulen
2
Affects Status Importance Assigned to Milestone
Launchpad itself
Triaged
Low
Unassigned

Bug Description

We sometimes need to list items in the UI that are short enough to render as running text, but have enough templating in them not to belong in browser code.

A single macro ought to let us generate comma-separated lists of things that each take fmt:url and such to render.

Advanced versions could do things like add an "and" where appropriate ("x and y" but also "x, y, and z"); cut the list short with an ellipsis if it gets too long ("alpha, beta, gamma, delta, epsilon, zeta, ..."); let the user "fold" long lists; or provide other navigation aids.

mpt has been using "tal:comma" for cases where he'd want a macro like this, so if we ever implement this, grep the templates for that.

Changed in launchpad:
status: New → Confirmed
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

This TAL pattern produces "X" or "X, and Y" or "X, Y, and Z" etc:

<!-- (suppress whitespace)
  --><tal:loop repeat="item view/items"><!-- (suppress whitespace)
    --><tal:comma condition="repeat/item/index">,
      <tal:and condition="repeat/item/end"> and </tal:end>
    </tal:comma>

    Item text<!-- (suppress whitespace)
  --></tal:loop>

That's not ideal for the X/Y case if the text for X is brief and simple, because there will be a comma for that case. It does work well for more complex X though.

Curtis Hovey (sinzui)
Changed in launchpad-foundations:
importance: Undecided → Low
status: Confirmed → Triaged
Jonathan Lange (jml)
affects: launchpad-foundations → launchpad-web
Revision history for this message
Gavin Panella (allenap) wrote :

Fwiw, canonical.launchpad.helpers.english_list() joins lists of strings according to the advice in The Elements of Style. It has tests too. Might save someone a few minutes.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.