Jump to content

Template:Items list

From Wikinews, the free news source you can write!
[edit] Template documentation

Usage

This template helps to maintain a list of items embodied by templates, to which some uniform operation may be applied; for example, they may be a list of conditions under which various assistants should be offered.

Set up a template with the following format:

{{#invoke:TScope|append|items list
|<item-1>
|<item-2>
...
|<item-n>
}}<noinclude>
{{documentation}}
</noinclude>

where <item-k> are the names of the item-templates. (Btw, this would work just as well if instead of append one used override, prepend, or even drop.)

By default, when the list-template is viewed directly, it is displayed as a wiki-table, with the templates linked one-per-line using {{tl}}. When it is transcluded outside of template space, no text at all is generated unless it is given a parameter for-each, in which case the template named by that parameter is applied to the item-template-names one at a time (via Module:TScope#map).

The wiki-table view of the list-template may be modified by providing a subpage of the list-template, {{nowrap}{{FULLPAGENAME}}/display item}}; within the wiki-table, the template named by this parameter is applied to the item-templates one at a time (via Module:TScope#map) to generate pieces of the wikitable.

Examples

List content

{{#invoke:TScope|append|Items list
|items list/test/item-a
|items list/test/item-b
|items list/test/item-c
}}

with default item-handling would produce table

{{items list/test/item-a}}
{{items list/test/item-b}}
{{items list/test/item-c}}

(which may be seen functioning in-situ at {{items list/test/list-1}}).

Internals

When the list-template is being viewed in template space —which is likely to mean it's being viewed directly rather than transcluded— it's handled by subtemplate {{items list/table}}.

For dialog-based management of dynamic sets of conditional items, presuming each item would be represented by a template, three techniques were considered.

  • Represent the list by a category to which the items belong. This makes adding/removing items a strictly distributed operation, which may or may not be a good thing. However, it would require the managing dialog to repeatedly query membership of the category, which is expensive and for which, as of this writing, the available dialog-based interface is not particularly graceful.
  • Represent the list by a wikilisp data structure; perhaps a simple list of template names, or perhaps a nested list of some sort. This would be highly flexible, and would minimize syntactic overhead. However, it would not be possible to directly perform separate template operations on the elements of the list, because the template tools of Module:TScope have been deliberately designed to prevent branching template operations based on computation.
  • Represent the list by a template call, in which each item is a separate template parameter. This the only way to support mapping of template operations onto the list, because Module:TScope has been deliberately designed so it would be the only way. Unfortunately, because an ordinary template call cannot obtain template parameters in the context surrounding the call, this has to be done using the #invoke: magic word, entailing a rather messy cantrip at the top of the list-template. To keep this cantrip from ever getting any worse, overriding the default table display is handled by an optional subtemplate of the list-template, so the cantrip remains fixed syntactic overhead.

See also