Template:Blank: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
(Created page with "<nowiki></nowiki><noinclude> This empty template is useful for introducing spaces or line breaks in places where they would normally be auto-removed. To explain why this is needed, let's look at the following code first: <pre> Paragraph 1 {{#if: condition | Paragraph 2 }} Paragraph 3 </pre> If all the conditions are met, it works fine: Paragraph 1 {{#if: condition | Paragraph 2 }} Paragraph 3 But if some of the conditions aren't met, it will produce too m...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 14: Line 14:
</pre>
</pre>


If all the conditions are met, it works fine:
If all the condition is met, it works fine:


  Paragraph 1
  Paragraph 1
Line 24: Line 24:
  Paragraph 3
  Paragraph 3


But if some of the conditions aren't met, it will produce too much empty space, like this:
But if the condition isn't met, it will produce too much empty space, like this:


  Paragraph 1
  Paragraph 1
Line 45: Line 45:
</pre>
</pre>


That works exactly as desired when the conditions ''aren't'' met:
That works exactly as desired when the condition ''isn't'' met:


  Paragraph 1 {{#if: |
  Paragraph 1 {{#if: |
Line 54: Line 54:
  Paragraph 3
  Paragraph 3


But... When the conditions ''are'' met, it doesn't work as expected!  It does this weird thing instead:
But... When the condition ''is'' met, it doesn't work as expected!  It does this weird thing instead:


  Paragraph 1 {{#if: condition |
  Paragraph 1 {{#if: condition |
Line 63: Line 63:
  Paragraph 3
  Paragraph 3


Why does that happen?  It's because parser functions like {{code|#if}} strip all blanks (spaces and line breaks) that come before and after the first non-blank character in each section.  So the line breaks after {{code|<nowiki>{{#if: condition |</nowiki>}} are completely ignored!
Why does that happen?  It's because parser functions like {{code|#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 {{code|<nowiki>{{#if: condition |</nowiki>}} are completely ignored!


This can be solved with the following trick.  Note the use of the empty {{code|nowiki}} tag:
This can be solved with the following trick.  Note the use of the empty {{code|nowiki}} tag:
Line 88: Line 88:
Paragraph 3
Paragraph 3
</pre>
</pre>
Result:
Paragraph 1 {{#if: condition | {{blank}}
Paragraph 2
}}
Paragraph 3
</noinclude>
</noinclude>

Latest revision as of 22:01, 2 August 2023

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

To explain why this is needed, let's look at the following code first:

Paragraph 1

{{#if: condition |
Paragraph 2
}}

Paragraph 3

If all the condition is met, it works fine:

Paragraph 1

Paragraph 2

Paragraph 3

But if the condition isn't met, it will produce too much empty space, like this:

Paragraph 1



Paragraph 3

Let's try to improve on this by making sure we don't introduce empty paragraphs:

Paragraph 1 {{#if: condition |

Paragraph 2
}}

Paragraph 3

That works exactly as desired when the condition isn't met:

Paragraph 1 

Paragraph 3

But... When the condition is met, it doesn't work as expected! It does this weird thing instead:

Paragraph 1 Paragraph 2

Paragraph 3

Why does that happen? It's 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 completely ignored!

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

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

Paragraph 2
}}

Paragraph 3

The empty tag ends the blank auto-removal at the point it's inserted, so the line breaks that come after are not ignored.

It's tedious to write <nowiki></nowiki> every time, so you can instead use this blank template, which can fulfill the exact same purpose:

Paragraph 1 {{#if: condition | {{blank}}

Paragraph 2
}}

Paragraph 3

Result:

Paragraph 1 

Paragraph 2

Paragraph 3