Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


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  














Template:Item






Аԥсшәа
العربية
Авар
تۆرکجه

 / Bân-lâm-gú
Беларуская (тарашкевіца)

Bosanski
Corsu
Eesti
فارسی
Frysk

Gungbe
/Hak-kâ-ngî
Հայերեն
Hrvatski
Bahasa Indonesia
Íslenska

Ladin

Bahasa Melayu
 / Mìng-dĕ̤ng-nḡ

Nederlands
Norsk nynorsk

Português

Simple English
کوردی
Српски / srpski
 


Українська
اردو
 

Edit links
 









Template
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




In other projects  



Wikidata
Wikiversity
 
















Appearance
   

 





Permanently protected template

From Wikipedia, the free encyclopedia
 


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.

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.


The code of the called template {{User:Petr Matas/sandbox/Pets}} is:

These are {{{owner}}}'s pets:
{{#invoke:Item|each|template=Show pet|
|*}}
They have {{#invoke:Item|gather|parameter=legs|template=Sum}} legs in total.
  • The code of the 1st used template {{Show pet}} is:
{{{name}}} is a {{{animal}}}{{#if:{{{legs|}}}| with {{{legs}}} legs}}.
  • The code of the 2nd used template {{Sum}} is:
{{#invoke:math|sum}}

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


Retrieved from "https://en.wikipedia.org/w/index.php?title=Template:Item&oldid=872453727"

Categories: 
Lua-based templates
Wikipedia utility templates
Hidden category: 
Wikipedia semi-protected templates
 



This page was last edited on 7 December 2018, at 07:48 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki