Help:テンプレート
作成
テンプレートとはTemplate:
」で
テンプレートの
こんにちは! ウィキへようこそ。
はじめてのテンプレートが
{{Welcome}}
{{Welcome}}
と
{{Welcome}}
を
こんにちは、皆 さん! この素敵 なウィキへようこそ。
その
これが
使用 法
テンプレートは、
{{
—名前 }}上記 で説明 したように、このテキスト (一般 的 には「テンプレート呼 び出 し」と呼 ばれます) は、ページ名 が Template:名前 となっているページの内容 で動的 に置換 されます (「参照 読 み込 み」(トランスクルージョン) と呼 ばれるプロセス)。これはテンプレート呼 び出 しを含 むページが読 み込 まれる たびに行 われます (つまり、ウィキの読者 がそのページを閲覧 するときに)。 Because the template call remains in the pages's source, any subsequent change to Template:Name will be seen on the page containing the template call. Also, the page will be listed among those that "link to" the template.{{subst:
— この名前 }}種類 のテンプレート呼 び出 しが使用 されると、それはテンプレート呼 び出 しを含 むページが保存 される時点 での Template:名前 の内容 の静的 なコピー に置換 されます。 That is, a copy of the contents of Template:Name will be substituted for the template call. No link is maintained between the page and the template, so each can be edited further without affecting the other. In effect, there is little difference between substituting the content in this way and simply typing it into the page's source "manually".{{safesubst:
— これは、テンプレートが名前 }}他 のテンプレートやパーサー関数 を呼 び出 す場合 に再帰 的 な置換 を許可 するために導入 されました。詳細 情報 は Help:Subst展開 を参照 してください。{{msgnw:
— これは、それを名前 }}含 むページが表示 される際 に、テンプレートの内容 を生 のウィキ構文 として表示 します (<nowiki>
がするのと同 じ方法 )。
{{Template:ページ
は「Template:Pagename」という名 }}名前 のページを参照 読 み込 みします ({{ページ
と名 }}同等 )。{{Talk:ページ
は「Talk:ページ名 }}名 」という名前 のページを参照 読 み込 みします{{:ページ
は「ページ名 }}名 」という名前 のページ (標準 名前 空間 内 ) を参照 読 み込 みします{{subst::ページ
は「ページ名 }}名 」という名前 のページを参照 読 み込 みします
{{Foo:Bar}}
は Template:Foo:Bar を参照 読 み込 みします
パラメータ
MediaWikiは、
つぎのような、ちょっとした
この
ノートがどこで
'''感謝 をこめて...'''
{{{1}}}。
{{{2}}}より。
{{{1}}}
と{{{2}}}
の{{{ }}}
に
ページからテンプレートを|
)で
名前 なしパラメータ
{{Thankyou|あなたの尽力 に|私 }}
この{{Thankyou}}
テンプレートが{{{1}}}=あなたの
と{{{2}}}=
というパラメータを
{{Thankyou|私 |あなたの尽力 に}}
{{{1}}}
など) によるパラメータの
数値 パラメーター
{{Thankyou|2=私 |1=あなたの友情 に}}
{{Thankyou}}
は、パラメータ{{{1}}}=your friendship
と{{{2}}}=Me
を
例
<span lang="en" dir="ltr" class="mw-content-ltr">{{Thankyou|1=adding “=”|2=Me}}</span>
名前 付 きパラメータ
パラメータを
{{{reason}}}に'''感謝 をこめて...'''。 ありがとうございます。{{{signature}}}より
テンプレート{{{reason}}}
と{{{signature}}}
を
{{Thankyou|signature=私 |reason=ありのままのあなたに}}
この{{Thankyou}}
テンプレートが{{{reason}}}=ありのままのあなたに
と{{{signature}}}=
というパラメータを
{{Thankyou|signature=私 |Reason=ありのままのあなたに|reason=大文字 と小文字 の区別 をしてくれて}}
テンプレートに
既定 値
パラメータを
{{Thankyou}}
'''感謝 をこめて...'''
{{{reason|すべてに}}}。
{{{signature|私 }}}より。
{{{reason|すべてに}}}
は、パラメータ {{{reason}}}
にすべてに
が{{{signature|
では、パラメータ {{{signature}}}
の
になります。さて、
{{foo|bar=}}
or {{foo|bar=|baz=qux}}
, the foo template considers the bar
parameter to be ""
. This is different from omitting the parameter altogether, which leaves it undefined and triggers the default value mechanism described above.{{#if:{{{1|}}}|{{{1|}}}|undefined}}
returns undefined if the parameter is either undefined or empty, while {{{1|undefined}}}
does so only if the parameter is undefined.{{{a|{{{b|}}} }}}
の
評価
This has a few consequences.
First of all, if you have a Template:Start
containing {{mytemplate
, and a Template:End
containing |foo=bar}}
, and put {{start}}{{end}}
on a page, mytemplate isn't transcluded, because tokens like "|" cannot be added by a template and keep their special meaning in templates.
You can still use templates to control the name of a parameter or template, but you cannot split a template call amongst multiple templates.
The second consequence of this is dead-code elimination.
If you make a template call like {{foo|{{DISPLAYTITLE:Bar}} }}
, and Template:Foo does not contain {{{1}}}, then the displaytitle is not used, since it is only evaluated when needed, and there is no parameter to substitute it into, so it is never evaluated.
This usually comes into play when using Extension:ParserFunctions, and can be especially noticed when used in combination with the int:
magic word that varies by user language.
Template calls starting with the magic word subst:
or safesubst:
are evaluated in a separate first pass that only happens at save time, along with ~~~~ and links using the pipe trick.
If they cannot be evaluated during the first pass, subst:
calls are ignored, and safesubst:
are treated as if a normal template.
Many but not all parser functions, parser tags and trancluded special pages are not directly included like templates but instead are replaced by a "strip marker". This means you cannot manipulate the results with parser functions like padleft: or similar functions from extensions, as they see the strip marker instead of the result of the parser function.
テンプレートの再帰
テンプレートa {{Aaaa}} z
であれば、"a a Template loop detected: Template:Aaaa z z "と
Forbidden idiom
This safeguard precludes a potentially useful template idiom where a template self-normalizes its own calling arguments.
In this forbidden example template:d
can either be called {{d|20200311}}
or {{d|y=2020|m=3|d=11}}
.
If called in the first manner, it recurses into itself with the second argument structure (obtained using string parser functions), which then follows a unified processing path.
{{#if:{{{1|}}}|{{d|y={{#sub:{{{1}}}|0|4}}|m={{#sub:{{{1}}}|4|2}}|d={{#sub:{{{1}}}|6|2}}}}|<!-- processing path with arguments y,m,d regardless of original call pattern -->}}
If template:d
is modified to recurse into template:d/2
and template:d/2
is an identical manual copy of template:d
this idiom works fine as the self-recursion safeguard operates dynamically and not statically.
A feasible way for the MediaWiki software to loosen the self-recursion rule would be to require that each recursive call have a distinct argument count from all previous active calls, at most once recursing with the argument count non-decreasing. That would provide a strong guarantee against infinite self-recursion while enabling useful idioms such as the one described here in a flexible manner.
If the processing path is of low complexity, a simple solution using only one template is to handle each calling convention on a separate if/else branch, duplicating the logic of the processing path within each case. If the processing path is more complex, each call-structure case can delegate to an implementation template with a unified call structure which provides the final template behaviour.
Tables in parameters
Since the pipe character (|
) and equality sign (=
) have different meanings in template calls and wikitables, in order to use table markup in the value of a template parameter one generally needs to "escape" those characters (i.e., protect them from interpretation as template markup) using special sequences:
- the built-in magic word
{{!}}
provides an "escaped" version of|
since MediaWiki 1.24 - the built-in magic word
{{=}}
provides an "escaped" version of=
since MediaWiki 1.39
Before the introduction of these magic words, many wikis used templates to accomplish the same things. On such a wiki, the magic words take precendence over the same-named templates.
Example table
A | B | C |
---|---|---|
A1 | B1 | C1 |
A2 | B2 | C1 |
Table code:
{| class=wikitable
!A!!B!!C
|-
|A1||B1||C1
|-
|A2||B2||C1
|}
Escaped table code:
{{{!}} class{{=}}wikitable
!A!!B!!C
{{!}}-
{{!}}A1{{!}}{{!}}B1{{!}}{{!}}C1
{{!}}-
{{!}}A2{{!}}{{!}}B2{{!}}{{!}}C2
{{!}}}
Note that the first left-brace ({
) is interpreted as a literal left-brace character because it is immediately followed by the {{!}}
magic word.
Similarly, the last right-brace (}
) is interpreted as a literal right-brace character because it is immediately preceeded by the same magic word.
However, in some cases these brace characters do cause problems, so some wikis provide templates for escaping these characters, as well:
- the template call
{{(}}
might provide an "escaped" version of{
- the template call
{{)}}
might provide an "escaped" version of}
Some wikis go even further and provide other convenience templates like {{(!}}, {{!)}}, {{!!}}. On such a wiki, the code can be simplified a bit to this form:
{{(!}} class{{=}}wikitable
!A!!B!!C
{{!}}-
{{!}}A1{{!!}}B1{{!!}}C1
{{!}}-
{{!}}A2{{!!}}B2{{!!}}C2
{{!)}}
テンプレートの参照 読 み込 みの制御
<noinclude>
、<includeonly>
、<onlyinclude>
のタグを
<noinclude>
と</noinclude>
の
<includeonly>
です。<includeonly>
と</includeonly>
の
- テンプレートを
含 むページのカテゴリ割 り当 て。注 :この方法 で一 つのテンプレートが割 り当 てる複数 のカテゴリを変更 した場合 でも、参照 ページのカテゴリはすぐには更新 されないことにご注意 ください。ジョブ キュー によって処理 されるからです。特定 のページのカテゴリを強制 的 に更新 するには、ページを編集 モードで開 き、何 も修正 しないまま保存 し直 します。 - テンプレートのページ
自体 を閲覧 しても、コードが処理 されないようにします。パラメータを与 えないとコードが処理 されない仕組 みのため、パラメータを与 えられないままテンプレートが作動 すると望 ましくない結果 をもたらします。
<noinclude>
タグと<includeonly>
タグの
<onlyinclude>
タグの
これらのタグは
テンプレートの整理
テンプレートが
特別 ページ >全 ページをクリックし、名前 空間 :一覧 で Template を選択 して表示 をクリック。
<noinclude> ==使 い方 ==利用 者 を歓迎 する記述 : {{Thankyou|reason=あなたの理由 |signature=あなたの署名 }} </noinclude>
その
While editing a page, a list of all templates used is available under the editing form, in a collapsible section titled "このページで
テンプレートへのリンク
テンプレートページはほかのウィキページ[[Template:Navbar]]
を
{{tl|Navbar}}
というコードを
この{{[[Template:Navbar|Navbar]]}}
も{{tl}}
のほうが
別 のウィキへのコピー
テンプレートはCSSかその
MediaWiki のコード
元 のウィキのSpecial:Exportに移動 し、必要 なすべてのテンプレートの完全 な履歴 を含 む.xmlファイルを次 のようにダウンロードします。大 きなテキストボックスにテンプレートの名前 を入力 します(例 :「Template:Welcome」)。大文字 と特殊 文字 に特 に注意 してください。テンプレート名 が正確 でない場合 、エクスポートは引 き続 き行 われますが、.xmlファイルには予期 されたデータが含 まれません。- 「テンプレートを
含 める」を選択 する。 項目 「完全 な履歴 は含 めず、最新 版 のみを含 める」を選択 する。- 「
書 き出 し」をクリック。
新 しいウィキの Special:Import に移動 して、.xml ファイルをアップロードします。
- もととなるウィキから
複製 したいテンプレートに移動 します。編集 画面 に移動 し、ウィキテキスト全体 をコピーします。 新 たなウィキにて、コピーしたテンプレートと同 じ名称 のページへ移動 します。作成 、編集 を押 してコピーしたソースを貼 り付 けします。各 テンプレートの編集 要約 欄 では、帰属 用 に複製 元 のページへリンクさせてください。編集 画面 での複製 元 ウィキに戻 り、編集 欄 の下 にある「このページで使 われているテンプレート」の一覧 をご確認 ください。そこに列挙 されたテンプレート1件 ごとに、上記 の処理 を繰 り返 します。また、一覧 のテンプレートから呼 び出 されるテンプレートにも、それぞれ同 じ処理 が必要 です。
拡張 機能
テンプレートで
テンプレート、{{#invoke: }}
が
CSS および JavaScript のコード
MediaWikiコードの
- テンプレートの
文 内 にCSSクラスが使 われているかどうか確認 (例 :class="foobar"
)。元 のウィキの「MediaWiki:Common.css」ないしは「MediaWiki:Monobook.css」の中 にCSSクラスがある場合 は、これらを複写 先 のウィキの「MediaWiki:Common.css」に複写 、テンプレートが予想 通 りに作動 するかどうか確認 をお願 いします。 - それでも
複写 したテンプレートが予想 通 りに作動 しない場合 には、元 のウィキの「MediaWiki:Common.js」もしくは「MediaWiki:Monobook.js」にコードがないかどうか確 かめます。コードが見 つかったら、それらをテンプレートの複写 先 のウィキの「MediaWiki:Common.js」に複写 することもできます。通常 、信頼 できる情報 源 からのみコードを複写 することが良識 的 で、まず関連 のある部分 を特定 するためにコードをウェブで検索 してみましょう。コメントから、コードの各 部分 の機能 を見極 めるヒントが見 つかるかもしれません。
関連 項目
General template usage
- w:Help:Template – a little more detail than here
- m:Help:Template – テンプレートがどう
機能 するか、より詳 しく具体 的 に示 した説明 文書 - m:Help:Advanced templates – さらに
高度 な技術 。動的 テンプレート呼 び出 しや可変 パラメーター名 など(訳注 : テンプレート内 にテンプレートやパラメータを組 み込 む等 )
Special constructs used in templates
- Help:マジックワード – ある
種 のテンプレートに備 わった上級 者 向 け機能 - Help:Extension:ParserFunctions – #ifや#switchなど、その
他 の上級 者 向 け機能 - Help:テンプレート
内 でのパーサー関数 – テンプレートのパラメーターにパーサー関数 を適用 する方法 - Help:テンプレートデータ
Other relevant information
- Help:テンプレート
展開 - Help:
外部 検索 –特殊 なテンプレートの例 - Manual:Importing Wikipedia infoboxes tutorial
- Extension:PageTemplates
- Manual:テキストをプリロードしてページを
作 る – Using templates as the starting text of a page - Help:
参照 読 み込 み –Template:
を使 わず、名前 空間 からページ内 に別 のページを埋 め込 む方法 。
外部 リンク
- ミラヘーズテンプレートリポジトリ - MediaWiki のテンプレートは
一般 的 な使用 を目的 としています。