Template:Ptl

From Moegirlpedia
Jump to: navigation, search
Template-info.svg Template Documentation  [View] [Edit] [History] [Refresh]

Introduction

This template can simulate the behaviour of a template to solve the problems such as code duplication.

Usage

<!-- Template declaration -->
{{ptl|define=<template name>|tl=<nowiki>
<template code>
<!-- Parameter usage -->
<!-- All parameter names would ignore the leading and trailing spaces which is consistent with a Wikitext template -->
{{{ 1 }}}                         <!-- An anonymous parameter -->
{{{ name }}}                      <!-- A named parameter -->
{{{ 2 | default value }}}         <!-- An anonymous parameter with default value -->
{{{ 3 | {{{ age | 14 }}} }}}      <!-- Nested usage -->
</nowiki>
}}

<!-- Template use -->
{{ptl|use=<template name>|<parameters>...}}
  • Template code should be wrapped with <nowiki>.
  • If you need to use the pipe symbol (|), you can use {{!}} instead.
  • If a parameter is not passed a value or set a default value, the code of this parameter would be regarded as a string, which is consistent with a Wikitext template.

Abbreviation

  • You can ignore the parameter use, which would call the template called last time.
  • If no template was called before, then the latest defined template would be called.

Examples

Example 1

{{ptl|define=plus|tl=<nowiki>
{{#expr:{{{1 | 0}}} + 1}}
</nowiki>}}
{{ptl}}

{{ptl|10}}

Result:

1

11

Example 2

{{ptl|define=rect|tl=<nowiki>
<div style="width:{{{width | 100px}}}; height:{{{height | 100px}}}; background:{{{color | #eee}}};"></div>
</nowiki>}}
{{ptl|define=round|tl=<nowiki>
<div style="width:{{{width | 100px}}}; height:{{{height | 100px}}}; background:{{{color | orange}}}; border-radius:50%;"></div>
</nowiki>}}

{{ptl}}

{{ptl|use=rect|color=blue}}

Result: