Difference between revisions of "User:Ericb/Use"
(experiment with template, in sandbox this time) |
m (link to live version) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | <noinclude>''This page was my playground before creating [[Template:Use]]'' | |
− | + | Since this wiki [[:User_talk:Giorgio_Sintichakis|lacks Extension:ParserFunctions]] such as {{#if:test|if text|if empty}}, it is desirable to provide an alternate syntax for conditional expansion (choosing one of two strings depending on whether the test string is empty, or choosing one of two strings depending on whether the test string matches a target string). This template is the workhorse behind conditional templates, and exploits some characteristics of named parameters - namely, if a parameter is named more than once, then the last use of that name is valid; and the calling page can use parameter expansions to control which named parameters this template will see. | |
− | <includeonly>{{{use}}}</includeonly> | + | |
+ | This macro understands up to two named parameters, and ignores all others. If the named parameter "indir" is given, then its value is an indirection that gives the other named parameter whose value will be used as the overall expansion. Otherwise, the value of the named parameter "use" will be the overall expansion. Examples: | ||
+ | <nowiki>{{use|use=hello}}</nowiki> gives "hello" | ||
+ | <nowiki>{{use|use=first|use=second}}</nowiki> gives "second" | ||
+ | <nowiki>{{use|indir=name|name=hello}}</nowiki> gives "hello" | ||
+ | </noinclude><includeonly>{{{{{{indir|use}}}|}}}</includeonly> |
Latest revision as of 12:19, 25 October 2011
This page was my playground before creating Template:Use
Since this wiki lacks Extension:ParserFunctions such as {{#if:test|if text|if empty}}, it is desirable to provide an alternate syntax for conditional expansion (choosing one of two strings depending on whether the test string is empty, or choosing one of two strings depending on whether the test string matches a target string). This template is the workhorse behind conditional templates, and exploits some characteristics of named parameters - namely, if a parameter is named more than once, then the last use of that name is valid; and the calling page can use parameter expansions to control which named parameters this template will see.
This macro understands up to two named parameters, and ignores all others. If the named parameter "indir" is given, then its value is an indirection that gives the other named parameter whose value will be used as the overall expansion. Otherwise, the value of the named parameter "use" will be the overall expansion. Examples:
{{use|use=hello}} gives "hello" {{use|use=first|use=second}} gives "second" {{use|indir=name|name=hello}} gives "hello"