: In MediaWiki, how to make a template that will not display anything when variable is null? I defined a template that should link to a page when the the variable is non-empty: [http://openlibrary.org/works/XXX/{{{ISBN}}}
I defined a template that should link to a page when the the variable is non-empty:
[http://openlibrary.org/works/XXX/{{{ISBN}}} {{{ISBN|}}}]
But what's not working as perfectly is that when the variable ISBN is not given a value, a non-functional link is still displayed. How to improve this?
More posts by @BetL925
1 Comments
Sorted by latest first Latest Oldest Best
Assuming you have the ParserFunctions extension, you can use the #if function, as documented on MediaWiki:
This function evaluates a test string and determines whether or not it is empty. A test string containing only white space is considered to be empty.
{{#if: test string | value if test string is not empty | value if test string is empty (or only white space) }}
The template you described would look something like this, that is, the link is only displayed if the ISBN parameter is not empty:
{{#if: {{{ISBN|}}} | [http://openlibrary.org/works/XXX/{{{ISBN}}} {{{ISBN|}}}] }}
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.