• Home
  • Random
  • Log in
  • Settings
  • About Safer nicotine wiki
  • Disclaimers
Safer nicotine wiki

Template:Item

  • Language
  • Watch
  • View source
Template documentation[view] [edit] [history] [purge]
This template uses Lua:
  • Module:Item

This template packs structured data into a compact item, which can be passed as a parameter to another template. This allows to pass multiple structured items to that template, which can iterate over the items and extract data from them.

Contents

  • 1 Usage
  • 2 Constructs available to recipient templates
    • 2.1 Get a component of an item
    • 2.2 Format an item using a template
    • 2.3 Format each item using a template
    • 2.4 Gather given parameter from all items
  • 3 See also

Usage

The structured data item contains all parameters (both numbered ones and named ones) passed to the {{Item}} template. For example, {{Item|Alice|Bob|best=Eve}} creates an item with components 1=Alice, 2=Bob, best=Eve.

Multiple items will be passed to an example recipient template {{User:Petr Matas/sandbox/Pets}} like this:

Markup Renders as
{{User:Petr Matas/sandbox/Pets|owner=Bob
| {{Item|name=Tom|animal=cat|legs=4}}
| {{Item|name=Jerry|animal=mouse|legs=4}}
| {{Item|name=Tweety|animal=bird|legs=2}}
}}

These are Bob's pets:

  • Tom is a cat with 4 legs.
  • Jerry is a mouse with 4 legs.
  • Tweety is a bird with 2 legs.

They have 10 legs in total.

Constructs available to recipient templates

Get a component of an item

See Template:Component.

Format an item using a template

See Template:Format item.

Format each item using a template

In the recipient template, use:

{{#invoke:Item|each|template=TransformationTemplate|Separator|Prefix|Suffix|...}}

This transforms all items using a given template. TransformationTemplate is called for each item with the parameters that the item has been created with, plus any additional parameters passed to #invoke (see {{Format item}} for details). The transformed items are separated with Separator and surrounded with Prefix and Suffix (whitespace is not stripped from these three optional parameters).

The template {{User:Petr Matas/sandbox/Pets}} from the example produces the list of pets using the following code (note the use of newline as a Separator and * as a Prefix to produce list items):

{{#invoke:Item|each|template=Show pet|
|*}}

Gather given parameter from all items

In the recipient template, use {{#invoke:Item|gather|parameter=ParameterName|template=TransformationTemplate}} to gather the given parameter from all items. TransformationTemplate will be called once and the gathered parameters (one parameter from each item) will be passed to it.

The template {{User:Petr Matas/sandbox/Pets}} from the example produces the total number of legs using {{#invoke:Item|gather|parameter=legs|template=Sum}}.

See also

  • {{For loop}}
The above documentation is transcluded from Template:Item/doc. (edit | history)
Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this template.
Retrieved from "https://safernicotine.wiki/mediawiki/index.php?title=Template:Item&oldid=1886"
Last edited on 7 November 2025, at 15:38
Cookies help us deliver our services. By using our services, you agree to our use of cookies.
More information

Languages

      This page is not available in other languages.

      Safer nicotine wiki
      • Creative Commons Attribution-ShareAlike
      • Powered by MediaWiki
      • Monitored by WikiApiary
      • ipv6 ready
      • Powered by Semantic MediaWiki
      • This page was last modified on 7 November 2025, at 15:38. Warning: Page may not contain recent updates.
      • Content is available under Creative Commons Attribution-ShareAlike unless otherwise noted.
      • Privacy policy
      • About Safer nicotine wiki
      • Disclaimers
      • Terms of Use
      • Desktop
      • Data access
      • Developers
      • Statistics
      • Cookie statement