Mobile app version of vmapp.org
Login or Join
BetL925

: 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}}}

@BetL925

Posted in: #Mediawiki

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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @BetL925

1 Comments

Sorted by latest first Latest Oldest Best

 

@Rivera981

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|}}}] }}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme