Help:Argument declaration in templates

From semantic-mediawiki.org
Jump to: navigation, search
Argument declaration in templates
Argument declaration in templates
Further Information
Provided by: Semantic MediaWiki
Minimum version: 1.4.0
Maximum version: still supported
Function: yes
Tag: no
Name: #declare
Table of Contents

The parser function #declare allows to "declare" template parameters.

So if you are using the Template:City in Paris, you would write:

{{City
|pop=12,000,000
|country=France
|mayor=Pierre Lala
}}

Then in the template, one could have used [[population::{{{population}}}]] in order to annotate the city with the population, thus making the already complicated template syntax even more complicated.

Now, instead of making those annotations, you just keep the templates as they are, and add a declare block in them, like this:

{{#declare:population=pop
|location=country
|mayor=mayor
}}

The left hand side of = is the property, the right hand side the template parameter name that is used to fill that property.

The actual idea is to allow to declare template parameters just as in programming languages that declare parameters in function declarations. This should allow, in the long run, for much better handling of templates, both from a content quality side as well as from a user interface side. For now, it allows for simpler template code.

See also: Setting values


This documentation page applies to all SMW versions from 1.4.0 to the most current version.
      Other languages: zh-hans

Help:Argument declaration in templates en 1.4.0