0

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

[[CODE-{{{CODE|}}}|{{{CODE|}}}]]

fails the second requirement. Any ideas?

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

1 Answer 1

1

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)

6
  • This does not work in a template.
    – qazwsx
    Commented Oct 16, 2014 at 20:14
  • How are you calling your template and passing it the value of CODE? Commented Oct 17, 2014 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
    Commented Oct 17, 2014 at 17:03
  • That is odd. Have you got a link to the live example of your template? Commented Oct 17, 2014 at 20:15
  • Ah. Looks like that wiki doesn't have the ParserFunctions extension installed. That extension is required for #if to work. Commented Oct 18, 2014 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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