Template:Void: Difference between revisions

Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
m
Text replacement - "<br>" to "<br/>"
m (Protected "Template:Void": Widely used page ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite)))
m (Text replacement - "<br>" to "<br/>")
 
Line 7: Line 7:
==Importance==
==Importance==
This template is critical for the proper functioning various parser functions. Specifically switch cases. Normally the #switch function cannot properly distinguish a null value from the default value. This template works around that.
This template is critical for the proper functioning various parser functions. Specifically switch cases. Normally the #switch function cannot properly distinguish a null value from the default value. This template works around that.
::When using this: <b><nowiki>{{#switch:{{{1|}}}|{{Void}}={{Void}}|Yes}}</nowiki></b>, it will always work.<br>
::When using this: <b><nowiki>{{#switch:{{{1|}}}|{{Void}}={{Void}}|Yes}}</nowiki></b>, it will always work.<br/>
::When using this: <b><nowiki>{{#switch:{{{1|}}}| |Yes}}</nowiki></b>, it won't work because the function will think that both the blank space and the "yes" are what the default value is. And the "yes" overrides the blank space.<br>
::When using this: <b><nowiki>{{#switch:{{{1|}}}| |Yes}}</nowiki></b>, it won't work because the function will think that both the blank space and the "yes" are what the default value is. And the "yes" overrides the blank space.<br/>
Here are some examples of this issue:
Here are some examples of this issue:
:Using the void template:
:Using the void template:
::<div class="messagebox" style="margin: 12px 0px; background-color: #1f4973; style="width: 5em; border: solid 1px #3b587e; padding: 5px;">{{#switch:{{{1|}}}|{{Void}}={{Void}}|Yes}}</div>
::<div class="messagebox" style="margin: 12px 0px; background-color: #1f4973; style="width: 5em; border: solid 1px #3b587e; padding: 5px;">{{#switch:{{{1|}}}|{{Void}}={{Void}}|Yes}}</div>
:Using a blank space:  
:Using a blank space:  
::<div class="messagebox" style="margin: 12px 0px; background-color: #1f4973; style="width: 5em; border: solid 1px #3b587e; padding: 5px;">{{#switch:{{{1|}}}| |Yes}}</div><br>
::<div class="messagebox" style="margin: 12px 0px; background-color: #1f4973; style="width: 5em; border: solid 1px #3b587e; padding: 5px;">{{#switch:{{{1|}}}| |Yes}}</div><br/>
In some cases however, there are other ways to work around this problem. Even in the above example. However these workarounds are less intuitive and make the coding more difficult to read and understand. Above you could replace the blank space with a single equals sign and it will work correctly. However, as stated before, this can be problematic with complex code. In cumbersome templates with lengthy switch cases this singular blank case with the equals sign can be potentially confusing and subjected to accidental removal in edits. It works as shown:
In some cases however, there are other ways to work around this problem. Even in the above example. However these workarounds are less intuitive and make the coding more difficult to read and understand. Above you could replace the blank space with a single equals sign and it will work correctly. However, as stated before, this can be problematic with complex code. In cumbersome templates with lengthy switch cases this singular blank case with the equals sign can be potentially confusing and subjected to accidental removal in edits. It works as shown:
*<b><nowiki>{{#switch:{{{1|}}}|=Blank|Not Blank}}</nowiki></b>
*<b><nowiki>{{#switch:{{{1|}}}|=Blank|Not Blank}}</nowiki></b>
**<div class="messagebox" style="margin: 12px 0px; background-color: #1f4973; style="width: 5em; border: solid 1px #3b587e; padding: 5px;">{{#switch:{{{1|}}}|=Blank|Not Blank}}</div>
**<div class="messagebox" style="margin: 12px 0px; background-color: #1f4973; style="width: 5em; border: solid 1px #3b587e; padding: 5px;">{{#switch:{{{1|}}}|=Blank|Not Blank}}</div>


The code <b><nowiki>{{ns:0}}</nowiki></b> also behaves like void. But is also counter-intuitive and can make template coding potentially confusing.<br>  
The code <b><nowiki>{{ns:0}}</nowiki></b> also behaves like void. But is also counter-intuitive and can make template coding potentially confusing.<br/>  
So all in all this template exists for readability and convienience of the codes in the edit view. It's largely harmless to keep.
So all in all this template exists for readability and convienience of the codes in the edit view. It's largely harmless to keep.
{{Cat|Workaround Templates}}</noinclude>
{{Cat|Workaround Templates}}</noinclude>

Navigation menu