Terraria Wiki
Terraria Wiki
Template-info.svg Dokumentation Die folgende Dokumentation stammt von der Seite Vorlage:Options/Dokumentation. (bearbeiten | Versionsgeschichte)
Siehe auch die englische Vorlagenseite: Template:Options. Sie enthält möglicherweise umfassendere oder aktuellere Informationen.
Important.svg Diese Seite ist nicht oder unvollständig übersetzt.
Hilf mit, indem du den Text übersetzt und anschließend diesen Hinweis entfernst. Dies entfernt diese Seite auch aus der Liste von Seiten mit unzureichender Übersetzung.

A common options mechanism for templates.



The configuration of options must be registered before the options can be used. It can be done via {{options/init}}, for example(It will be used for all following examples as well):

{{options/init|item<!-- init config for "item" namespace
-->|key:icons=yes<!--  declare an option named "icons", and its default value is "yes"
-->|key:small=no<!-- default value of "small" option is "no"
-->|value:small:n=no<!-- value "n" for "small" is same as "no", so {{options/set|item|small=n}} is same as {{options/set|item|small=no}}
-->|key:style=<!-- default value of "style" is empty value.
-->|alias:css=style<!-- "css" is an alias of "style", so {{options|item|css}} is same as {{options|item|style}}

It is possible to have it load automatically("autoload") via Template:<namespace>/initOptions. For example, for {{options|icon|small}}, it will try to transclude Template:item/initOptions.

Get/set options

Get: {{options/get|<namespace>|<key>}} or {{options|<namespace>|<key>}}

Set: {{options/set|<namespace>|<key1>=<value1>|<ke2>=<value2>|...}} or {{options|<namespace>|<key1>=<value1>|<key2>=<value2>|...}}

Note: The latter form is a bit slow, but more handy for writing. For using in templates the former is prefer, and for using in articles both are ok.


{{options/get|item|icons}}<!-- get default value -->
{{options/set|item|icons=no}}<!-- set it to "no" -->
{{options/get|item|icons}}<!-- now it will be "no" -->
{{options/set|item|icons=all|small=yes}}<!-- set multiple options -->

It will output: yes no all yes


It is possible to save current state of options to a snapshot, then restore it later.




-->{{options|item|icons}} {{options/get|item|small}} <!-- aa bb 
-->{{options|item|icons}} {{options/get|item|small}} <!-- xx yy 
-->{{options|item|icons}} {{options/get|item|small}} <!-- aa bb -->

It will output: aa bb xx yy aa bb

There is a special snapshot created during initialization, it can be restored via {{options/reset|<namespace>}}