Difference between revisions of "Template:Ptl"

From Moegirlpedia
Jump to: navigation, search
(Created page with "<includeonly><!-- -->{{#if:{{{define|}}}|{{#vardefine:ptl.templates.{{{define|}}}|{{{tl|}}}}}{{#vardefine:ptl.saveCalled|{{{define|}}}}}|<!-- -->{{#if:{{{use|{{#var:ptl.saveCa...")
 
 
Line 1: Line 1:
 
<includeonly><!--
 
<includeonly><!--
 
-->{{#if:{{{define|}}}|{{#vardefine:ptl.templates.{{{define|}}}|{{{tl|}}}}}{{#vardefine:ptl.saveCalled|{{{define|}}}}}|<!--
 
-->{{#if:{{{define|}}}|{{#vardefine:ptl.templates.{{{define|}}}|{{{tl|}}}}}{{#vardefine:ptl.saveCalled|{{{define|}}}}}|<!--
-->{{#if:{{{use|{{#var:ptl.saveCalled}}}}}|{{#invoke:pageTemplate|main|tl={{#var:ptl.templates.{{{use|{{#var:ptl.saveCalled}}}}}}}}}{{#vardefine:ptl.saveCalled|{{{use|{{#var:ptl.saveCalled}}}}}}}|{{error|错误的页内模板使用}}}}}}<!--
+
-->{{#if:{{{use|{{#var:ptl.saveCalled}}}}}|{{#invoke:pageTemplate|main|tl={{#var:ptl.templates.{{{use|{{#var:ptl.saveCalled}}}}}}}}}{{#vardefine:ptl.saveCalled|{{{use|{{#var:ptl.saveCalled}}}}}}}|{{error|Wrong in-page template usage}}}}}}<!--
 
--></includeonly><noinclude>{{doc}}</noinclude>
 
--></includeonly><noinclude>{{doc}}</noinclude>

Latest revision as of 19:47, 30 April 2022

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: