Template:Void

From bg3.wiki
Jump to navigation Jump to search
Template documentation

This empty template is useful for introducing spaces or line breaks in places where they would normally be auto-removed.

Note: The same effect can be achieved with <nowiki/>, but that works slightly differently: It produces content that passes as non-empty with regards to {{#if:}} and similar checks, whereas the result of this template is truly empty and thus passes as a 'false' value.

To explain why this {{void}} or <nowiki/> hack is needed, let's look at the following example:

Paragraph 1

{{#if: condition |
Paragraph 2
}}

Paragraph 3

If the condition is met, that works fine; but if it isn't met, it will produce too much empty space:

Markup Renders as
Paragraph 1

{{#if: condition |
Paragraph 2
}}

Paragraph 3

Paragraph 1

Paragraph 2

Paragraph 3

Paragraph 1

{{#if: |
Paragraph 2
}}

Paragraph 3

Paragraph 1


Paragraph 3

We can try to improve on this by making sure we don't introduce empty paragraphs, but there's another issue as seen here:

Markup Renders as
Paragraph 1 {{#if: condition |

Paragraph 2
}}

Paragraph 3

Paragraph 1 Paragraph 2

Paragraph 3

Paragraph 1 {{#if: |

Paragraph 2
}}

Paragraph 3

Paragraph 1

Paragraph 3

This happens because parser functions like #if strip all blanks (spaces and line breaks) that come before the first non-blank character, and after the last non-blank character. So, the line breaks after {{#if: condition | are ignored.

This can be solved with the following trick. Note the use of the empty nowiki tag:

Markup Renders as
Paragraph 1 {{#if: condition | <nowiki/>

Paragraph 2
}}

Paragraph 3

Paragraph 1

Paragraph 2

Paragraph 3

The empty nowiki tag prevents the auto-removal of the line break and makes this work as desired.

This leaves one potential problem, which is creating an entire sequence of lines, or none at all, depending on multiple conditions. This example uses Extension:Arrays:

Markup Renders as
{{#arraydefine: A | one, two, three }}{{#arrayprint: A | | @@ | <nowiki/>

{{#if: true | Line @@ }}
}}

Line one

Line two

Line three

If all the conditions aren't met, then this produces some content consisting only of some nowiki tags, which are sometimes enough to make it count as non-empty, based on peculiarities of how some parser functions work. For example, array functions break it:

Markup Renders as
If it were a sequence of if checks, it would work:

{{#lvardef: content |
{{#if: <!--false--> | <nowiki/>

Line one
}}{{#if: <!--false--> | <nowiki/>

Line two
}}
}}{{#if: {{#lvar:content}} |
Header that should only appear if content is non-blank.

{{#lvar:content}}
}}

If it were a sequence of if checks, it would work:


But using array functions breaks it:

{{#lvardef: content |
{{#arraydefine: A | one, two, three }}{{#arrayprint: A | | @@ | <nowiki/>

{{#if: <!--false--> | Line @@ }}
}}
}}{{#if: {{#lvar:content}} |
Header that should only appear if content is non-blank.

{{#lvar:content}}
}}

But using array functions breaks it:

Header that should only appear if content is non-blank.

The void template fixes this issue:

Markup Renders as
{{#lvardef: content |
{{#arraydefine: A | one, two, three }}{{#arrayprint: A | | @@ | {{void}}

{{#if: <!--false--> | Line @@ }}
}}
}}{{#if: {{#lvar:content}} |
Header that should only appear if content is non-blank.

{{#lvar:content}}
}}