Difference between revisions of "User:Ericb/Use"
(experiment with indirection) |
(improve docs) |
||
Line 1: | Line 1: | ||
− | <noinclude> | + | <noinclude>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 describes 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> |
Revision as of 12:45, 24 October 2011
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 describes 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"