[go: nahoru, domu]

Jump to content

Help:XML-style tags

From mediawiki.org
Revision as of 18:45, 16 July 2024 by Network-charles (talk | contribs) (I created a complete MediaWiki equivalent for the m:Help:XML-style tags page on MetaWiki.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
PD Note: When you edit this page, you agree to release your contribution under the CC0. See Public Domain Help Pages for more info. PD

XML-style tags use this syntax:

<tagname attribute1="value1" attribute2="value2"> content </tagname >

Parser extension tags

On any wiki, the Special:Version page shows the available parser extension tags in alphabetical order.

On MediaWiki, the tags are as follows:

<categorytree>, <ce>, <charinsert>, <chem>, <dynamicpagelist>, <gallery>, <graph>, <hiero>, <imagemap>, <indicator>, <inputbox>, <langconvert>, <languages>, <mapframe>, <maplink>, <math>, <nowiki>, <phonos>, <poem>, <pre>, <ref>, <references>, <rss>, <score>, <section>, <source>, <syntaxhighlight>, <templatedata>, <templatestyles> and <timeline>

The special:version page also has a list of installed parser hooks, which allow more dynamic content to be included on any page.

Other standard tags exist but they aren't defined in the special:version page. They include:

Tag function

You can use the parser function #tag which is a way to create custom HTML tags in MediaWiki in the following ways:

{{#tag:tagname|content}}
{{#tag:tagname|content|attribute1=value1}}
{{#tag:tagname|content|attribute1=value1|attribute2=value2}}

Other ways can be used too.

First, identify the wikitexts for the content, the attribute names, and the values, and expand each. If two attributes, attribute1, and attribute2, have the same name values, keep the value of the second one and discard the first. This is similar to template calls but different from the #switch function, where "a=b|a=c" is considered equivalent to "a=b".

Below is an example before expansion:

{{#tag:tagname}}
{{#tag:tagname||attribute1=value1}}
{{#tag:tagname||attribute1=value1|attribute2=value2}}
{{#tag:tagname|content}}
{{#tag:tagname|content|attribute1=value1}}
{{#tag:tagname|content|attribute1=value1|attribute2=value2}}

After expansion:

<tagname/>
<tagname attribute1="value1"/>
<tagname attribute1="value1" attribute2="value2"/>
<tagname> content </tagname >
<tagname attribute1="value1"> content </tagname >
<tagname attribute1="value1" attribute2="value2"> content </tagname >

After the first "|", content is fixed, and "=" within the expanded wikitext has no special significance. The entire text is used regardless. If the content has a "|", write it as {{!}}, except in contexts like [[...|...]]. For example, write external links in a timeline as [...{{!}}...].

The tag function is a useful alternative to XML-style tags because it doesn't expand the wikitext for content and attributes. It allows parameters, variables, parser functions, and templates. For nowiki and pre-tags, the choice depends on what effect you want, but for most other extensions, the tag function is more versatile. However, double braces in the content can cause parsing issues, which can be fixed by adding a space between the braces. For simple tags like <references/>, using {{#tag:references}} offers little benefit.

Other

See also