「ヘルプ:Templates」を編集中
この編集を取り消せます。
下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
1行目: | 1行目: | ||
− | + | {{PD Help Page}} | |
− | {{ | + | |
+ | <languages/> | ||
+ | |||
<translate> | <translate> | ||
<!--T:1--> | <!--T:1--> | ||
− | If you have standard texts you want to include on several pages, the MediaWiki template feature comes into play | + | If you have standard texts you want to include on several pages, the MediaWiki template feature comes into play. |
− | |||
− | |||
− | |||
== Creation == <!--T:2--> | == Creation == <!--T:2--> | ||
46行目: | 45行目: | ||
<!--T:15--> | <!--T:15--> | ||
− | * <code><nowiki>{{Name}}</nowiki></code> — as described above, this link will be dynamically replaced by the current content of <nowiki>[[Template:Name]]</nowiki> at the time the page with the template link is | + | * <code><nowiki>{{Name}}</nowiki></code> — as described above, this link will be dynamically replaced by the current content of <nowiki>[[Template:Name]]</nowiki> at the time the page with the template link is loaded. The link will remain unchanged in the page's source. |
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:16--> | <!--T:16--> | ||
− | * <code><nowiki>{{subst:Name}}</nowiki></code> — when this template link is used, it will be replaced once and for all with the content of <nowiki>[[Template:Name]]</nowiki> as of the time the page with the link is '''saved''': a copy of the contents of <nowiki>[[Template:Name]]</nowiki> will be ''substituted'' for the template link. The contents are then a part of the including page, and can be edited normally, separately from the original. ''Note'': | + | * <code><nowiki>{{subst:Name}}</nowiki></code> — when this template link is used, it will be replaced once and for all with the content of <nowiki>[[Template:Name]]</nowiki> as of the time the page with the link is '''saved''': a copy of the contents of <nowiki>[[Template:Name]]</nowiki> will be ''substituted'' for the template link. The contents are then a part of the including page, and can be edited normally, separately from the original. ''Note'': changes to the source template page will ''not'' be propagated to the page with the template link. |
</translate> | </translate> | ||
<translate> | <translate> | ||
96行目: | 95行目: | ||
<!--T:30--> | <!--T:30--> | ||
− | The thank you note will have a reason (in this case, "all your effort") and a signature ("Me"). Your objective is that any user | + | The thank you note will have a reason (in this case, "all your effort") and a signature ("Me"). Your objective is that any user is able to thank any other user, for any reason whatsoever. |
<!--T:31--> | <!--T:31--> | ||
So that the note will look similar everywhere it is used, you can define a template called [[Template:Thankyou]], for example. Although the note should look similar whenever a user thanks another user, its specific contents (i.e. the reason and the signature) will be different. For that reason, you should pass them as parameters. If we ignore the remaining elements to format the box and place the image, the core content of the template will be this: | So that the note will look similar everywhere it is used, you can define a template called [[Template:Thankyou]], for example. Although the note should look similar whenever a user thanks another user, its specific contents (i.e. the reason and the signature) will be different. For that reason, you should pass them as parameters. If we ignore the remaining elements to format the box and place the image, the core content of the template will be this: | ||
− | |||
− | + | <!--T:32--> | |
− | + | <pre><nowiki>'''A little thank you...''' | |
− | '''A little thank you...''' | ||
for {{{1}}}. | for {{{1}}}. | ||
− | hugs, {{{2}}}</ | + | hugs, {{{2}}}</nowiki></pre> |
− | </ | ||
− | |||
<!--T:33--> | <!--T:33--> | ||
Notice the use of <tvar|1><code><nowiki>{{{1}}}</nowiki></code></> and <tvar|2><code><nowiki>{{{2}}}</nowiki></code></>. This is the way to identify, within templates, the parameters that will be passed in when the template is used. Note that, within the template, each parameter is surrounded by '''three''' braces: <tvar|braces><code><nowiki>{{{ }}}</nowiki></code></>. This is different from normal template name usage. | Notice the use of <tvar|1><code><nowiki>{{{1}}}</nowiki></code></> and <tvar|2><code><nowiki>{{{2}}}</nowiki></code></>. This is the way to identify, within templates, the parameters that will be passed in when the template is used. Note that, within the template, each parameter is surrounded by '''three''' braces: <tvar|braces><code><nowiki>{{{ }}}</nowiki></code></>. This is different from normal template name usage. | ||
144行目: | 139行目: | ||
<!--T:44--> | <!--T:44--> | ||
'''Note:''' identifying parameters by order (with <code><nowiki>{{{1}}}</nowiki></code>, etc) works ''only'' with anonymous parameters. If your page identifies any parameter by number or name, as shown below, this method will no longer be available to the template which receives them. | '''Note:''' identifying parameters by order (with <code><nowiki>{{{1}}}</nowiki></code>, etc) works ''only'' with anonymous parameters. If your page identifies any parameter by number or name, as shown below, this method will no longer be available to the template which receives them. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Numbered parameters === <!--T:45--> | === Numbered parameters === <!--T:45--> | ||
205行目: | 191行目: | ||
<!--T:61--> | <!--T:61--> | ||
Since no parameters were passed in, the template presents the parameters themselves, instead of their respective values. In these cases, it may be useful to define ''default'' values for the parameters, i.e. values that will be used if no value is passed in. For example, if the template contents are changed to: | Since no parameters were passed in, the template presents the parameters themselves, instead of their respective values. In these cases, it may be useful to define ''default'' values for the parameters, i.e. values that will be used if no value is passed in. For example, if the template contents are changed to: | ||
− | |||
− | + | <!--T:62--> | |
− | + | <pre><nowiki>'''A little thank you...''' | |
− | '''A little thank you...''' | ||
for {{{reason|everything}}}. | for {{{reason|everything}}}. | ||
− | hugs, {{{signature|Me}}}</ | + | hugs, {{{signature|Me}}}</nowiki></pre> |
− | </ | ||
− | |||
<!--T:63--> | <!--T:63--> | ||
then <code><nowiki>{{{reason|everything}}}</nowiki></code> defines that if no parameter <code>{{{reason}}}</code> is provided, then the value <code>everything</code> will be used. Similarly, <code><nowiki>{{{signature|Me}}}</nowiki></code>, defaults parameter <code>{{{signature}}}</code> to value <code>Me</code>. Now, transcluding the template again without passing any parameter, results in the following: | then <code><nowiki>{{{reason|everything}}}</nowiki></code> defines that if no parameter <code>{{{reason}}}</code> is provided, then the value <code>everything</code> will be used. Similarly, <code><nowiki>{{{signature|Me}}}</nowiki></code>, defaults parameter <code>{{{signature}}}</code> to value <code>Me</code>. Now, transcluding the template again without passing any parameter, results in the following: | ||
220行目: | 202行目: | ||
<!-- strictly speaking, this example is false, because the template call was changed to obtain the desired effect - but the effect is the same if the template is defined as described --> | <!-- strictly speaking, this example is false, because the template call was changed to obtain the desired effect - but the effect is the same if the template is defined as described --> | ||
<translate> | <translate> | ||
− | <!--T: | + | <!--T:64--> |
{{Thankyou|reason=everything|signature=Me}} | {{Thankyou|reason=everything|signature=Me}} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Control template inclusion == <!--T:65--> | == Control template inclusion == <!--T:65--> | ||
306行目: | 235行目: | ||
<!--T:74--> | <!--T:74--> | ||
− | Everything outside <tvar|noinclude><code><nowiki><noinclude></nowiki></code></> and <tvar|includeonly><code><nowiki><includeonly></nowiki></code></> is processed and displayed normally; that is, both when the template page is being viewed directly and when the template is included in another page | + | Everything outside <tvar|noinclude><code><nowiki><noinclude></nowiki></code></> and <tvar|includeonly><code><nowiki><includeonly></nowiki></code></> tags is processed and displayed normally; that is, both when the template page is being viewed directly and when the template is included in another page. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Organizing templates == <!--T:75--> | == Organizing templates == <!--T:75--> | ||
333行目: | 244行目: | ||
<!--T:77--> | <!--T:77--> | ||
To find them, users can: | To find them, users can: | ||
− | # Click ''' | + | # Click '''Special Pages > All Pages''' |
− | # In the ''' | + | # In the '''Namespace''' list, choose '''Template''' and click '''Go'''. |
<!--T:78--> | <!--T:78--> | ||
349行目: | 260行目: | ||
<!--T:80--> | <!--T:80--> | ||
Then, an editor can simply copy and paste the example to use the template. | Then, an editor can simply copy and paste the example to use the template. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Copying from one wiki to another == <!--T:81--> | == Copying from one wiki to another == <!--T:81--> | ||
372行目: | 269行目: | ||
<!--T:84--> | <!--T:84--> | ||
− | If you have import rights | + | If you have import rights on the new wiki: |
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:85--> | <!--T:85--> | ||
− | # Go to | + | # Go to [[Special:Export]] on the original wiki, and download an .xml file with the complete history of all necessary templates, as follows: |
</translate> | </translate> | ||
<translate> | <translate> | ||
384行目: | 281行目: | ||
<translate> | <translate> | ||
<!--T:87--> | <!--T:87--> | ||
− | #* Check the box " | + | #* Check the box "Include templates". |
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:88--> | <!--T:88--> | ||
− | #* '''Uncheck''' the box " | + | #* '''Uncheck''' the box "Include only the current revision". |
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:89--> | <!--T:89--> | ||
− | #* Click | + | #* Click Export. |
</translate> | </translate> | ||
<translate> | <translate> | ||
400行目: | 297行目: | ||
<!--T:91--> | <!--T:91--> | ||
If you don't have import rights on the new wiki: | If you don't have import rights on the new wiki: | ||
− | + | </translate> | |
− | <!--T: | + | <translate> |
− | # Go to | + | <!--T:92--> |
− | # | + | # Go to [[Special:Export]] on the original wiki, and download an .xml file with the latest version only of all necessary templates, as follows: |
− | # | + | </translate> |
− | + | <translate> | |
− | <!--T: | + | <!--T:93--> |
− | + | #* Enter the name of the template in the big text box. | |
+ | </translate> | ||
+ | <translate> | ||
+ | <!--T:94--> | ||
+ | #* Check the box "Include templates". | ||
+ | </translate> | ||
+ | <translate> | ||
+ | <!--T:95--> | ||
+ | #* '''Check''' the box "Include only the current revision". | ||
+ | </translate> | ||
+ | <translate> | ||
+ | <!--T:96--> | ||
+ | #* Click Export. | ||
+ | </translate> | ||
+ | <translate> | ||
+ | <!--T:97--> | ||
+ | #* Open the file in a text editor and replace certain [[w:en:XML entity|XML entities]] with the corresponding characters: &lt; → <, &gt; → >, &quot; → " and &amp; → &. Because of XML syntax rules, these entities appear in the XML file, but they should not appear in the edit box of the MediaWiki instance. | ||
+ | </translate> | ||
<translate> | <translate> | ||
− | <!--T: | + | <!--T:98--> |
− | + | #* Manually copy the text inside the <tvar|text><code><nowiki><text></nowiki></code></> tag of each listed template into a similarly named template in your wiki. In the edit summary of each template, link to the original page for attribution. | |
− | <!--T: | + | <!--T:99--> |
− | + | This will copy the entire code necessary, and will suffice for some templates. | |
=== Extensions === <!--T:100--> | === Extensions === <!--T:100--> | ||
426行目: | 340行目: | ||
<!--T:104--> | <!--T:104--> | ||
− | Besides MediaWiki code, many templates make use of CSS and some rely on JavaScript to work fully. If the copied templates are not behaving as expected, this may be the cause. To copy the required CSS and JavaScript to your wiki you'll normally need to have admin | + | Besides MediaWiki code, many templates make use of CSS and some rely on JavaScript to work fully. If the copied templates are not behaving as expected, this may be the cause. To copy the required CSS and JavaScript to your wiki you'll normally need to have admin priviledges, because you'll be editing system messages in the "MediaWiki:" namespace. |
<!--T:105--> | <!--T:105--> | ||
− | # Look for the use of CSS classes (text like <code>class="foobar"</code>) in the template text. If those classes appear in "MediaWiki:Common.css" or "MediaWiki:Monobook.css" on the original wiki, copy | + | # Look for the use of CSS classes (text like <code>class="foobar"</code>) in the template text. If those classes appear in "MediaWiki:Common.css" or "MediaWiki:Monobook.css" on the original wiki, copy them to "MediaWiki:Common.css" on the new wiki and check if the template is now fine. |
+ | </translate> | ||
<translate> | <translate> | ||
<!--T:106--> | <!--T:106--> | ||
# If the copied template is still not working as expected, check if there is code in "MediaWiki:Common.js" or "MediaWiki:Monobook.js" on the original wiki. If so, you can try copying it to "MediaWiki:Common.js" on the new wiki. Normally, it is a good idea to only copy code from trusted sources, and first browsing the code to identify and select the parts that are relevant. You may find comments that can serve as clues to identify the functionality of each part. | # If the copied template is still not working as expected, check if there is code in "MediaWiki:Common.js" or "MediaWiki:Monobook.js" on the original wiki. If so, you can try copying it to "MediaWiki:Common.js" on the new wiki. Normally, it is a good idea to only copy code from trusted sources, and first browsing the code to identify and select the parts that are relevant. You may find comments that can serve as clues to identify the functionality of each part. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== See also == <!--T:107--> | == See also == <!--T:107--> | ||
− | |||
− | |||
− | |||
<!--T:108--> | <!--T:108--> | ||
− | * | + | * [[Special:MyLanguage/Help:External searches]] – a template special use case example |
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:109--> | <!--T:109--> | ||
− | * | + | * [[Special:MyLanguage/Help:Magic words]] – fancy stuff you may find in some templates |
+ | </translate> | ||
+ | <translate> | ||
+ | <!--T:110--> | ||
+ | * [[Special:MyLanguage/Help:Parser functions in templates]] | ||
</translate> | </translate> | ||
− | |||
<translate> | <translate> | ||
<!--T:111--> | <!--T:111--> | ||
− | * | + | * {{meta|Help:Template}} – contains a much more thorough manual on how exactly templates function |
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:112--> | <!--T:112--> | ||
− | ** | + | ** {{meta|Help:Advanced templates}} – describes even more advanced techniques such as dynamic template calls and variable variables |
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:113--> | <!--T:113--> | ||
− | * | + | * {{meta|Help:Embed page}} – embedding pages from [[Special:MyLanguage/Help:Namespaces|namespaces]] other than <code>Template:</code>. |
</translate> | </translate> | ||
− | |||
− | [[Category:Help{{ | + | [[Category:Help{{langcat|Templates}}|Templates]] |
− | [[Category:Template | + | [[Category:Template]] |
− |