Need some MediaWiki help - evaluation in a template
03-13-2021, 12:58 PM
(This post was last modified: 03-13-2021, 12:59 PM by robkelk.)
G'day! I can't figure out where on the MediaWiki site to ask for help with coding an evaluation in a template, so I'll start by asking here:
First question: Can I evaluate the value of one field based on the contents of a different field?
Second question: Can I use wildcards in an evaluation? If yes, what is the syntax of the wildcards?
The specific case:
I've imported the Wikipedia template "Infobox" to the freebie wiki and have written a template that uses it. Right now, my code for the "image" parameter in the calling template is an if/else check that displays the image if a parameter exists or adds a category if the parameter is blank:
|image = {{#if:{{{image|}}} |[[File:{{{image|}}}|250px]] |[[Category:Page Needing Image]]}}
I now have a request for a third case check in that line:
The value passed to "data1" will contain some but not all of a URL, one or two template calls, or a comment, with no way to know what order they'll be in.
I'm assuming that it's safe to nest "if" statements to create an if/elseif/else check. It's the "elseif" part of this that I'm having trouble with.
Any help with coding this evaluation would be appreciated...
First question: Can I evaluate the value of one field based on the contents of a different field?
Second question: Can I use wildcards in an evaluation? If yes, what is the syntax of the wildcards?
The specific case:
I've imported the Wikipedia template "Infobox" to the freebie wiki and have written a template that uses it. Right now, my code for the "image" parameter in the calling template is an if/else check that displays the image if a parameter exists or adds a category if the parameter is blank:
|image = {{#if:{{{image|}}} |[[File:{{{image|}}}|250px]] |[[Category:Page Needing Image]]}}
I now have a request for a third case check in that line:
- if no value is passed to "image", display nothing and add the category "Page Needing Image" to the page, exactly as above;
- elseif a value is passed to "image" and a value that contains a call to a template named "unavailable" is passed to "data1", display the file with a gray background;
- else, display the file with the default background, exactly as above.
The value passed to "data1" will contain some but not all of a URL, one or two template calls, or a comment, with no way to know what order they'll be in.
I'm assuming that it's safe to nest "if" statements to create an if/elseif/else check. It's the "elseif" part of this that I'm having trouble with.
Any help with coding this evaluation would be appreciated...
--
Rob Kelk
Sticks and stones can break your bones,
But words can break your heart.
Boycotting ALL products from the USA as long as that country's leader continues to lie about my native country.
Government of Canada: How to immigrate to Canada
Government of Canada: Claiming refugee protection (asylum) from within Canada
Rob Kelk
Sticks and stones can break your bones,
But words can break your heart.
Boycotting ALL products from the USA as long as that country's leader continues to lie about my native country.
Government of Canada: How to immigrate to Canada
Government of Canada: Claiming refugee protection (asylum) from within Canada

