I have a MediaWiki site with Semantic MediaWiki extension installed. I'd like to test if a string is empty. For that I do:
{{#if: {{{transcript.lncrna}}} | Yes | No}}
apparently, {{{transcript.lncrna}}} is empty, it contains nothing. However, the parser function #if
tells me Yes as an answer.
What is wrong?
A variable being empty, and a variable being undefined are two different things, when it comes to MediaWiki parser functions. In your case {{{transcript.lncrna}}}
most likely isn't defined. MediaWiki will then treat it literally like you are trying to write out the text “{{{transcript.lncrna}}}”, which, of course, makes the if-statement return true.
To check if a parameter is empty, you need to add an empty default value, writing {{{transcript.lncrna|}}}
(note the vertical bar):
{{#if: {{{transcript.lncrna|}}} | Yes | No}}
Here is a table with the different possibilities
value of {{{param}}}: undefined | empty | whitespace | something
--------------------------------------------------------------------------------
{{#if: {{{param|}}} | Yes | No}} | No | No | No | Yes
{{#if: {{{param}}} | Yes | No}} | Yes | No | No | Yes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With