Jump to content

Hilfe:ExpandTemplates

From mediawiki.org
This page is a translated version of the page Help:ExpandTemplates and the translation is 54% complete.
PD Hinweis: Wenn Du diese Seite bearbeitest, stimmst Du zu, dass Dein Beitrag unter CC0 veröffentlicht wird. Mehr Informationen findest du auf der Public Domain Hilfeseite.
Einige alte Überarbeitungen für diese Seite wurden unter der CC BY-SA-Lizenz importiert. Nur neue Beiträge sind PD (Public Domain).
PD
Screenshot of MediaWiki for translation purposes.
Screenshot von MediaWiki für die Übersetzung.

ExpandTemplates ermöglicht die rekursive Erweiterung von Vorlagen, Parserfunktionen und Variablen.

Die Seite Special:ExpandTemplates verfügt über zwei Eingabefelder, eines zur Eingabe von Wikitext und ein weiteres zur Eingabe eines Seitennamens. Es erzeugt im Fenster „Ergebnis“ den erweiterten Wikitext, d. h., Vorlagen, Parser-Funktionen und Variablen werden rekursiv erweitert; Variablen, die vom Seitennamen abhängen, werden auf der Grundlage des angegebenen Seitennamens erweitert. Dies ist ein Zwischenergebnis, bevor eine Seite nach dem Speichern oder Drücken von „Vorschau“ gerendert wird (oder der resultierende Wikitext einer weiteren Verarbeitung unterzogen wird). Es ist hilfreich zum Verständnis und zur Fehlerbehebung bei der Wikitext-Erweiterung. Es unterstützt keine Substitution (ein separater Erweiterungsprozess [ Transformation vor dem Speichern] wird nach der Eingabe von Wikitext in ein Bearbeitungsfenster und dem Klicken auf „Vorschau anzeigen” oder „Speichern”, aber vor der regulären Analyse durchgeführt; der resultierende Wikitext kann in einem beliebigen Bearbeitungsfenster durch Klicken auf „Änderungen anzeigen” oder durch Speichern einer Testseite und erneutes Öffnen des Bearbeitungsfensters überprüft werden). Wenn Sie eine Ersetzung verwenden müssen, verwenden Sie die Parse-API anstelle der ExpandTemplates-API und aktivieren Sie die Transformationen vor dem Speichern [dazu setzen Sie pst auf true].

Zusätzlich gibt es einen Vorschaubereich. Allerdings zeigt dies das gerenderte Ergebnis der nochmaligen Erweiterung des erweiterten Wikitextes (T30616). Obwohl das Ergebnis in der Regel dasselbe ist wie nach einer einfachen Erweiterung, kann es unterschiedlich sein, wenn die erste Erweiterung geschweifte Klammern erzeugt.

Das magische Wort '!' bietet eine Möglichkeit, "|" in einem Parameterwert einer Vorlage- oder Parserfunktion zu erlauben, insbesondere für den Einsatz in der Tabellensyntax. Diese Vorlage kann mit ExpandTemplates verwendet werden, um teilweise Erweiterung/Austausch durchzuführen.

Die Tabelle mit Template:2x zeigt, dass ein Aufruf mit einem Parameterseparator "|" in der Form {{!}} eine normale Erweiterung verhindert; die letzte Spalte zeigt den Vorschaubereich (mit dem Ergebnis der doppelten Erweiterung).

Verwendung

Original-Wikitext Erweiterter Wikitext Rendern Vorschau erstellt von ExpandTemplates
{{2x|[[MediaWiki]] }} [[MediaWiki]] [[MediaWiki]] MediaWiki MediaWiki MediaWiki MediaWiki
{{2x{{!}}[[MediaWiki]] }} {{2x|[[MediaWiki]] }} {{2x|MediaWiki }} MediaWiki MediaWiki
{{2x{{!{{!}}}}[[MediaWiki]] }} {{2x{{!|}}[[MediaWiki]] }} {{2x{{!|}}MediaWiki }} {{2x|MediaWiki }}

Kommentare entfernen

The "Remove comments" option selects whether comments are removed, not just in the final result but throughout the expansion process. This affects the result of parser functions: a comment in the expression of #expr or #ifexpr gives an error message unless "Remove comments" is on, and comments affect #if and ifeq.

Beispiel:

{{#expr:<!--p-->3}}

{{#ifeq:<!--p-->3|3|1|0}}

{{#if:<!--p-->|1|0}}

Normal expansion, and ExpandTemplates with "Remove comments" on:

3

1

0

Full substitution, and ExpandTemplates with "Remove comments" off:

Expression error: Unexpected < operator

0

1

XML-Parsebaum

Optionally the XML parse tree (the XML DOM representation of the wikitext, also called document tree or DOM tree) is shown (see also Handbuch:Preprocessor DOM.php ). Zum Beispiel:

a [[b|c]]
{{CURRENTYEAR}}
{{{{{a}}}}}
{{#ifeq:2|3|a|b}}
{{#switch:a|a=3|b=4|a=5}}
{{a|b|c=d[[e|f]]g|h}}
{{{a|b}}}
{{#tag:nowiki|a=b}}
{{#tag:nowiki|aeb}}

gives

<root>a [[b|c]]
<template lineStart="1"><title>CURRENTYEAR</title></template>
<template lineStart="1"><title><tplarg><title>a</title></tplarg></title></template>
<template lineStart="1"><title>#ifeq:2</title><part><name index="1"/><value>3</value></part><part><name index="2"/><value>a</value></part><part><name index="3"/><value>b</value></part></template>
<template lineStart="1"><title>#switch:a</title><part><name>a</name>=<value>3</value></part><part><name>b</name>=<value>4</value></part><part><name>a</name>=<value>5</value></part></template>
<template lineStart="1"><title>a</title><part><name index="1"/><value>b</value></part><part><name>c</name>=<value>d[[e|f]]g</value></part><part><name index="2"/><value>h</value></part></template>
<tplarg lineStart="1"><title>a</title><part><name index="1"/><value>b</value></part></tplarg></root>
<template lineStart="1"><title>#tag:nowiki</title><part><name>a</name>=<value>b</value></part></template>
<template lineStart="1"><title>#tag:nowiki</title><part><name index="1"/><value>aeb</value></part></template>

Thus:

  • The result shows a stage in processing before actual evaluation. Thus even names of variables, parser functions, and templates have not been determined. Also, the colon and "#" are not detected yet, so no distinction is made between variables, parser functions, and templates, let alone that there would be distinction between existing and non-existing variables, parser functions, and templates. Therefore:
    • Distinction is made between parameter items with and without "=", even though for some items of some parser functions it is treated as plain text after all.
    • "|a=b|a=c" is not reduced yet to "|a=c" because the fact that the left sides are equal is only known after their evaluation, and also because this reduction depends on the evaluation of title. For example, for titles of the form #switch:.., "|a=b|a=c" is equivalent to "|a=b" after all.
  • A pair of double rectangular brackets shields "|" from being interpreted as a parameter separator, but links are not shown separately in the tree.

Input text in URL

The wikitext serving as input can also be put in the URL, e.g., using urlencode, {{fullurl:special:ExpandTemplates|wpInput={{urlencode:{{texpr{{!}}abc}}}}}} gives //www.mediawiki.org/w/index.php?title=Special:ExpandTemplates&wpInput=%7B%7Btexpr%7Cabc%7D%7D. {{!}}, using {{!}}, prevents the template texpr from expanding in the URL, and also prevents "|" from being interpreted as a separator of the parameter of urlencode from a dummy second parameter. It can also be used in a template call without parameters, albeit that in the input box of ExpandTemplates this becomes a template with unnamed parameter {{{1}}} being the empty string instead of undefined; e.g. {{fullurl:special:ExpandTemplates|wpInput={{tc{{!}}}}}}. This does not work for variables and parser functions, use percent codes for one pair of braces instead (see wikitext); for the ParserFunctions prefix "#" use %23:

https://www.mediawiki.org/w/index.php?title=Special:ExpandTemplates&wpInput={{CURRENTTIME}}.

https://www.mediawiki.org/w/index.php?title=Special:ExpandTemplates&wpInput={{%23expr:2*3}}.

Beispiel

Query parameters
  • wpContextTitle=pagetitle
  • wpGenerateRawHtml=true
  • wpGenerateXml=true
  • wpInput=
  • wpRemoveComments=true
  • wpRemoveNowiki=true

URL:

Anpassung

Adjusting the box width

Standardmäßig beträgt die Breite der Eingabe- und Ergebnisbox nur 11 Zeichen. You may want to change this to full width by adding something like the following to your CSS:

textarea {
    border: 1px solid #2f6fab;
    color: Black;
    background-color: white;
    width: 100%;
    padding: 0.1em;
    overflow: auto;
}

Siehe auch