Template talk:IfEmpty

From RPGnet
Revision as of 12:00, 1 July 2014 by MattKendall (talk | contribs) (Created page with "Since wiki.rpg.new does not support the #if statement, this template provides "if like" functionality using a trick in the template engine. To utilize this template, type: <n...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Since wiki.rpg.new does not support the #if statement, this template provides "if like" functionality using a trick in the template engine. To utilize this template, type:

{{IfEmpty|{{{NameOfKey}}}=text that should appear when NameOfKey is empty|text that should appear when NameOfKey has a value}}

This logic works because IfEmpty outputs a single parameter, which is the empty string. If it is not present, then it outputs the first non-named parameter. The trick is that we pass through the **value** of the key that we want to analyze as a named parameter. So when the key has an empty value, you get:

=text that should appear when NameOfKey is empty
1=text that should appear when NameOfKey has a value

Because the empty string key is present, 'text that should appear when NameOfKey is empty' is outputted. However, if NameOfKey has a value, then IfEmpty is called with:

the value stored in NameOfKey=text that should appear when NameOfKey is empty
1=text that should appear when NameOfKey has a value

Because the empty string key is now missing, we output 'text that should appear when NameOfKey has a value'.


The only further trick is that every key used this way must be defined in the template. If it's not present, then the trick doesn't work.