In a MediaWiki template I'm making, I want to let it to become [[CODE-value]] when CODE=value is used and empty when CODE=value is not given in the actual page. The current version


fails the second requirement. Any ideas?

  • 1
    Have a look at {{#if}}. – svick Oct 1 '14 at 17:05
  • Using {{#if: {{{CODE}}} | [[CODE-{{{CODE}}}]] | (not applicable) }} in the template still does not work. Any additional hint? – qazwsx Oct 1 '14 at 21:50
  • I think you need {{#if: {{{CODE|}}}, so that the condition is empty when CODE is not set. – svick Oct 1 '14 at 22:11
  • That didn't work. I'm using this code in a template. That's probably problematic? – qazwsx Oct 1 '14 at 22:28

Make sure the ParserFunctions extension is installed.

Then put the following in a template, such as Template:Iftest

{{#if: {{{CODE|}}} | [[CODE-{{{CODE}}}]] | (not applicable) }}

If CODE-parameter is empty or not present you get (not applicable). i.e.

  • {{Iftest|CODE=123}} gives [[CODE-123]]

  • {{Iftest|CODE=}} gives (not applicable)

  • {{Iftest}} gives (not applicable)

| improve this answer | |
  • This does not work in a template. – qazwsx Oct 16 '14 at 20:14
  • How are you calling your template and passing it the value of CODE? – Lokal_Profil Oct 17 '14 at 7:33
  • Yes, I put the code you showed into a template, and created a new page applying the template with some value assigned to parameter CODE. It does not show desired output. – qazwsx Oct 17 '14 at 17:03
  • That is odd. Have you got a link to the live example of your template? – Lokal_Profil Oct 17 '14 at 20:15
  • Ah. Looks like that wiki doesn't have the ParserFunctions extension installed. That extension is required for #if to work. – Lokal_Profil Oct 18 '14 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.