Template:Template demo: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
(test)
 
(Added list style)
Line 1: Line 1:
<includeonly>{{#vardefine: i | 1 }}{| class="wikitable"
<includeonly>{{#vardefine: i | 1 }}{{#switch:{{{style|table}}}
! style="width:20%" | Code1
| table = <table class="wikitable">
! Code2
<tr>
! style="width:15%" | Result
<th>Markup</th>
<th>Renders as</th>
</tr>
{{#while:
{{#while:
| {{{{{#var: i }} |}}}
| {{{{{#var: i }} |}}}
| <nowiki />
| <tr><td>{{Demo|sep=</td><td>|nocat=yes|{{{ {{#var: i}} }}}}}</td></tr>
{{!}}-
{{#vardefine: i | {{#expr: {{#var: i }} + 1 }} }}
{{!}} <code><nowiki>{{{ {{#var: i }} }}}</nowiki></code>
}}</table>
{{!}} <code>{{#tag:nowiki|{{{{{#var: i }} }}}}}</code>
| list = {{#while:
{{!}} {{{ {{#var: i }} }}}
| {{{{{#var: i }} |}}}
| {{Demo|sep=Renders as:|nocat=yes|{{trim|{{{ {{#var: i}} }}}}}}}
{{#vardefine: i | {{#expr: {{#var: i }} + 1 }} }}
{{#vardefine: i | {{#expr: {{#var: i }} + 1 }} }}
}}
}}
|}</includeonly><noinclude>
| #default = Unknown style option <code>{{{style|}}}</code>. Expected <code>table</code> (default) or <code>list</code>.
}}</includeonly><noinclude>
This template is designed to easily demo template usage and is intended for use within template documentation pages. It lets you display a set of template examples with the markup and rendered output displayed side-by-side.


This is an attempt at making a template that produces a table of template usage examples for template documentation. This would replace manually written tables like [[Template:CharLink#Examples]] which involve copy-pasting the code for the template in both columns (which can easily get out of sync).
This template has two styles: a two-column table (<code>style = table</code>) and a list (<code>style = list</code>). The table is appropriate table is appropriate for shorter, inline templates. For larger templates, the list style may be preferred.


In the first column, the template parameters are not expanded {{em|at all}} before adding the nowiki tags. In the second column, the template is {{em|completely}} expanded before adding the nowiki tags. Is there a way to truncate template expansion so that it stops after two steps at {{InfoBlob|<nowiki>{{CharLink|Shadowheart}}</nowiki>}}?
As with [https://en.wikipedia.org/wiki/Template:Demo Template:Demo on Wikipedia], the arguments to this template {{em|must}} be wrapped in <code><nowiki><nowiki>...</nowiki</nowiki><nowiki>></nowiki></code> tags or the parameters with be expanded before being passed to this template.


== Examples ==
=== Table style ===
Select this style with <code>style = table</code>. It is also the default style used if the optional style parameter is omitted. This style should be used for shorter, inline templates that can fit nicely within a two-column table.
{{User:NtCarlson/Template:Example table
{{User:NtCarlson/Template:Example table
| {{CharLink|Shadowheart}}
| style = table
| {{CharLink|Shadowheart|Shart}}
| <nowiki>{{CharLink|Shadowheart}}</nowiki>
| <nowiki>{{DamageText|2d4 + 1|Fire}}</nowiki>
}}
 
=== List style ===
Select this style with <code>style = list</code>. This should be used to demo templates too large to fit within a table.
==== Output ====
{{User:NtCarlson/Template:Example table
| style = list
| <nowiki>
{{ImageQuote
| quote = The operations of these huge steel juggernauts are powered by engines of churning hellfire.
| image = Portrait Steel Watcher.png
| link = Adamantine Golem
}}
</nowiki>
| <nowiki>
{{ImageQuote
| quote = These levitating eyes transmit all that they see to the one who created them.
| image = Portrait Scrying Eye.png
| link = Scrying Eye
| height = 60px
| rounding = 20%
| font-size = 100%
}}
</nowiki>
}}
}}
</noinclude>
</noinclude>

Revision as of 23:02, 19 July 2024

This template is designed to easily demo template usage and is intended for use within template documentation pages. It lets you display a set of template examples with the markup and rendered output displayed side-by-side.

This template has two styles: a two-column table (style = table) and a list (style = list). The table is appropriate table is appropriate for shorter, inline templates. For larger templates, the list style may be preferred.

As with Template:Demo on Wikipedia, the arguments to this template must be wrapped in <nowiki>...</nowiki> tags or the parameters with be expanded before being passed to this template.

Examples

Table style

Select this style with style = table. It is also the default style used if the optional style parameter is omitted. This style should be used for shorter, inline templates that can fit nicely within a two-column table.

Markup Renders as
 {{CharLink|Shadowheart}}
Shadowheart Shadowheart
 {{DamageText|2d4 + 1|Fire}}
2d4 + 1Damage TypesFire

List style

Select this style with style = list. This should be used to demo templates too large to fit within a table.

Output

{{ImageQuote
| quote = The operations of these huge steel juggernauts are powered by engines of churning hellfire.
| image = Portrait Steel Watcher.png
| link = Adamantine Golem
}}
Renders as:
Portrait Steel Watcher.png
The operations of these huge steel juggernauts are powered by engines of churning hellfire.
{{ImageQuote
| quote = These levitating eyes transmit all that they see to the one who created them.
| image = Portrait Scrying Eye.png
| link = Scrying Eye
| height = 60px
| rounding = 20%
| font-size = 100%
}}
Renders as:
Portrait Scrying Eye.png
These levitating eyes transmit all that they see to the one who created them.