Difference between revisions of "Template:Conditional template call with newline/doc"

From blackwiki
Jump to navigation Jump to search
imported>Zyxw
m (Since <tt> is obsolete in HTML5, replace it with <kbd> – see HTML element#tt, Wikipedia:HTML5, and mw:Help:Extension:Linter/obsolete-tag. using AWB)
imported>Bsherr
m (→‎Sample 1: replacing Template:Tld with Template:Tlc, plus general and typo fixes as found)
 
Line 6: Line 6:
 
==Usage==
 
==Usage==
 
===Sample 1===
 
===Sample 1===
Example using [[Template:2x]], which simply repeats its argument twice, so <code><nowiki>{{2x|Pizza}}</nowiki></code> produces {{2x|Pizza}}.  One can combine this with {{tld|Conditional template call with newline}} in the following code
+
Example using [[Template:2x]], which simply repeats its argument twice, so <code><nowiki>{{2x|Pizza}}</nowiki></code> produces {{2x|Pizza}}.  One can combine this with {{tlc|Conditional template call with newline}} in the following code
  
 
<code><nowiki>{{#tag:pre|{{Conditional template call with newline|1|2x|Pizza}}{{Conditional template call with newline|0|2x|Bora}}{{Conditional template call with newline|1|2x|Bang}}}}</nowiki></code>
 
<code><nowiki>{{#tag:pre|{{Conditional template call with newline|1|2x|Pizza}}{{Conditional template call with newline|0|2x|Bora}}{{Conditional template call with newline|1|2x|Bang}}}}</nowiki></code>

Latest revision as of 22:50, 9 August 2020

This template calls template {{{2}}} with parameter {{{3}}} and adds a newline at the end, all under condition {{{1}}}. Successive calls should not be separated by a newline.

This templates has been used to avoid writing out the condition twice, once for the template call and once for the newline, but also Template:If can be used to preserve newlines.

Usage

Sample 1

Example using Template:2x, which simply repeats its argument twice, so {{2x|Pizza}} produces PizzaPizza. One can combine this with {{Conditional template call with newline}} in the following code

{{#tag:pre|{{Conditional template call with newline|1|2x|Pizza}}{{Conditional template call with newline|0|2x|Bora}}{{Conditional template call with newline|1|2x|Bang}}}}

which produces
PizzaPizza
BangBang

Notice how BoraBora is suppressed, and there is a newline between PizzaPizza and BangBang.

Sample 2

Sample usage with full substitution of the template to create a newline in wikitext.

1. Create a sample template : "Template:testnewline"

ABC{{<includeonly>subst:</includeonly>Conditional template call with newline|{{<includeonly>subst:</includeonly>#ifeq:{{{align|}}}|{{{align}}}|1|0}}|void|1|substctc=subst:|subst=subst:}}
DEF

2. When called empty ({{subst:testnewline}}), it generates the following wikitext:

ABC
DEF

3. When called as {{subst:testnewline|align=somevalue}}, it generates the following wikitext (note the newline):

ABC

DEF

Parameters

Mandatory parameters

1
1st unnamed parameter, a condition to be evaluated. Should result in 1 for true or 0 for false. One can use the result 0 or 1 directly. If the condition is true, the second template will be called and a newline added afterwards.
Sample condition: {{#ifeq:{{{align|}}}|{{{align}}}|1|0}}. The condition is true if the template is called with a parameter "align=somevalue", it's false if align is not included.
2
2nd unnamed parameter, the name of template to be called.
Can be "!" for Template:! or even "void" for Template:Void

Optional parameters

3
3rd unnamed parameter, value to be assigned to {{{1}}} when calling template {{{2}}}
substctc
for substitution of some parser functions and auxiliary templates called inside the template, use the value "subst:"; recommended when the template is substituted; note that in that case any parser functions or templates in the condition have to be substituted too.
subst
for substitution of template {{{2}}}, use the value "subst:"
p1n
name of an additional parameter used by template {{{2}}}
p1v
value to be assigned to {{{p1n}}} when calling template {{{2}}}