Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaWiki parser function #if for undefined template parameter

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?

like image 418
user2979409 Avatar asked Oct 09 '14 08:10

user2979409


1 Answers

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
like image 152
leo Avatar answered Sep 22 '22 03:09

leo