Help:Hide empty rows in table

From semantic-mediawiki.org
Semantic extension(s): Semantic MediaWiki · Semantic Forms
Further extension(s): Parser Functions
Keyword(s): conditional · empty · hide

Description:

Sometimes you are working with forms where not every field gets filled in. Maybe you would like to hide those fields in the display.

Here helps the #if parser function in the sense of "show only if not empty".

For this example, we are showing the results in a table. We hide the entire row of the corresponding field (including the heading to the empty field).

The table row how it usually looks within the template:

|-
! Form field name:
| {{{Formfield|}}}|[[Has property xy::{{{Formfield}}}]]

The same table row, but this time only showing when not empty:

{{#if: {{{Formfield|}}} | {{!-}}
! Form field name:
{{!}} {{#if: {{{Formfield|}}}|[[has property xy::{{{Formfield}}}]]}}
}}

See how the #if function is always embraced in double brackets:

{{#if: ...}}

Escaping table marks[edit]

The marks for the table structure need to be escaped with template calls within those brackets:

{{{!}}

and

{{!-}}

The template ! then says "|" [1] and the template !- says "|-".


Note[edit]

  1. Starting with MW 1.24 there is no longer a need to create a template called ! since this version introduces a "fixed" variable {{!}} which does the very same thing.