Topic on Project:Support desk

Jump to navigation Jump to search

Doubt with #if function

10
Summary by Jonathan3

{{!}} for |

MauCavans (talkcontribs)

Sorry if this is a stupid question, but I'm kinda new to mediawiki and couldn't find any useful info online.


I created a simple template, and wanted to make it so, when the first field is empty ({{{1|}}}), both colums are merged into one, showing "N/A".

Can't use colspan because of the #if funcion, and <span> doesn't seem to work either, acting only on the word and not on the whole field.

Here's an example on what the template looks like at the moment:

{| width="100%" class="sortable" style="text-align:center; background: #e1e1e1; border:3px solid #5b5a5a"

|- ! colspan="2" | Name |-

| style="background:#FFF" width="50%" | {{#if {{{1|}}}| {{{1|}}} | N/A}}

| style="background:#FFF" width="50%" | {{#if {{{2|}}}| {{{2|}}} | N/A}}

|}


Thank you in advance for the help.

PerfektesChaos (talkcontribs)

If you provided a literal copy, the reason is obvious: every parser function is separating by : from (first) parameter.

  • {{#if: condition | yeah }} will work.
MauCavans (talkcontribs)

No, this isn't a literal copy, my bad for the mistype.

My doubt was another:

- if the text string {{{1|}}} is not empty, I want the value to only occupy its column (as it does)

- if the text string {{{1|}}} is empty, I want one "N/A" to occupy both the columns

Doing {{#if: {{{1|}}}| {{{1|}}} |colspan="2"| N/A}} doesn't seem to work, as #if: function will take colspan="2" as third parameter.


As I said before, I'm pretty new to mediawiki, so sorry if there's an obvious way to do it that I don't know yet.

Bawolff (talkcontribs)

try

{{#if: {{{1|}}}| {{{1|}}} {{!}}colspan="2"|N/A }}

Bawolff (talkcontribs)

sometimes it will be easier to use html-style table syntax.


Also remember when using wiki style table syntax, you can use {{!}} if you need the | to go to the table layer.

Jonathan3 (talkcontribs)

This seems to do what you want:

{| class="wikitable"
|-
! colspan="2" | Name
|-
| {{#if: {{{1|}}} | {{{1}}} 
{{!}} {{{2|}}} | colspan="2" {{!}} N/A }}
|}

I've tested it with:

{{test template|a|b}}
{{test template|c|}}
{{test template||d}}
{{test template}}
MauCavans (talkcontribs)

Yes, thank you, that's exactly what I was looking for!


Strangely enough, the | style="background:#FFF" at the start of the line is what seems to be causing the bug. I'll have to look for another way around it.


Thanks a lot to all of you for the help!

Jonathan3 (talkcontribs)

Maybe it's the # symbol. You could try "background: white" or use a class and Common.css

MauCavans (talkcontribs)

Thank you, I fixed it by setting the same backgroun to every line:

{| width="100%" class="sortable" style="text-align:center; background: #e1e1e1; border:3px solid #5b5a5a"

|- ! colspan="2" | Name |- style="background=#FFF" | {{#if: {{{1|}}} | width="50%"{{!}}{{{1|}}} {{!}} width="50%"{{!}}{{{2|}}} | colspan="2"{{!}}N/A}} |}


Again, really really thanks for the help. This little thing was bugging me for so long.

Jonathan3 (talkcontribs)

You're welcome. It's nice to hear that something has helped.