ସହଯୋଗ:ଛାଞ୍ଚ
- To find lists of commonly used templates, see Wikipedia:Template messages.
ଛାଞ୍ଚ ହେଉଛି ଏକ ଉଇକିପିଡ଼ିଆ ପୃଷ୍ଠା ଯାହାକୁକି ଅନ୍ୟ ପୃଷ୍ଠାଗୁଡ଼ିକରେ ବ୍ୟବହାର କରିବାପାଇଁ ତିଆରି କରାଯାଇଥାଏ । ଛାଞ୍ଚଟିରେ ମୁଖ୍ୟତଃ ବାରମ୍ବାର ଲେଖାଯାଉଥିବା ଜିନିଷଗୁଡିକ ଯାହାକୁ ବହୁ ପୃଷ୍ଠାରେ ଲେଖିବାକୁ ପଡ଼େ ରଖାଯାଇଥାଏ । ଏଗୁଡ଼ିକ ମୁଖ୍ୟତଃ ପ୍ରାରମ୍ଭିକ ଲେଖା ଢାଞ୍ଚା, ସାଧାରଣ ଚେତାବନୀ, ନୋଟିସ, ଇନ୍ଫୋବାକ୍ସ କିମ୍ବା ନାଭିଗେସନଲ ବାକ୍ସରୂପେ ବ୍ୟବହୃତ ହୋଇଥାଏ ।
ସବୁଠାରୁ ଅଧିକ ଉପଯୋଗ କରାଯାଉଥିବା ବ୍ୟବହାରକୁ ଟ୍ରାନ୍ସକ୍ଲୁଜନ କୁହାଯାଏ । ଯେଉଁଥିରେ ଗନ୍ତବ୍ୟ ପୃଷ୍ଠାଟିର ୱିକିଟେକ୍ସଟ, {{ଛାଞ୍ଚର ନାମ}}
ଉପଯୋଗ କରି ଗୋଟିଏ ଛାଞ୍ଚର ଆଧାର ରଖିଥାଏ । ଆଉ ଗୋଟିଏ ଉପାୟ ହେଲା ସବଷ୍ଟିଚ୍ୟୁସନ୍, ଯେଉଁଥିରେ ସାଇତିବା ସମୟରେ ଗୋଟିଏ ପୃଷ୍ଠାର ଲେଖା ଗନ୍ତବ୍ୟ ପୃଷ୍ଠାର ୱିକିଟେକ୍ସଟରେ ରଖାଯାଇଥାଏ ।
ସାଧାରଣରେ
[ସମ୍ପାଦନା]ଅଧିକାଂଶ ଛାଞ୍ଚଗୁଡ଼ିକର ନାମ "ଛାଞ୍ଚ:<ଛାଞ୍ଚ ନାମ>" ଏହିଭଳି ପଦ୍ଧତିରେ ଲେଖାଯାଇଥାଏ । କିନ୍ତୁ ଏହା ବାଧ୍ୟତାମୂଳକ ନୁହେଁ, ଯେକୋୖଣସି ପୃଷ୍ଠାରୁ (ଯଥା ବ୍ୟବହାରକାରୀ ପୃଷ୍ଠା, ଆଲୋଚନା ପୃଷ୍ଠା ଇତ୍ୟାଦିରୁ) ଆପଣ ଛାଞ୍ଚ ବ୍ୟବହାର କରିପାରିବେ ।[୧]
ଗୋଟିଏ ଛାଞ୍ଚ ମଧ୍ୟ ଅନ୍ୟ ଏକ ଛାଞ୍ଚକୁ ବ୍ୟବହାର କରିପାରେ । ସେମାନଙ୍କର କିଛି ସୀମିତ ପରିମାଣର ପ୍ରୋଗ୍ରାମିଂ ଦକ୍ଷତା ଅଛି: ବଦଳକରାଯାଇପାରୁଥିବା ମୁଲ୍ୟ, ଗଣନ ଏବଂ ନିର୍ଦ୍ଧିଷ୍ଟ କେତେକ ଉଇକି ଶବ୍ଦ ଯଥା ଦିନ, ସମୟ ଏବଂ ପୃଷ୍ଠା ନାମ । କେତେକ ଛାଞ୍ଚରେ ଟ୍ୟାଗ ରହିଥାଏ, ଯାହା କେଉଁ ୱିକିଟେକ୍ସଟ କେତେବେଳେ ଟ୍ରାନ୍ସକ୍ଲୁଜନ ବା ସବଷ୍ଟିଚ୍ୟୁସନ୍ ହେବ ତାହା ଦର୍ଶାଇଥାଏ । ଏହାର ଅର୍ଥ ସବୁବେଳେ ଛାଞ୍ଚ ପୃଷ୍ଠାଟି ଗନ୍ତବ୍ୟ ପୃଷ୍ଠାରେ ବ୍ୟବହାର ହେଲାପରେ ଦିଆଯାଇଥିବା ୱିକିଟେକ୍ସଟ ବଦଳପରେ ସମାନ ଦେଖାଯାଇନଥାଏ ।
ଗୋଟିଏ ପୃଷ୍ଠାରେ ଛାଞ୍ଚ ଉପଯୋଗ କରିବା ନିମିତ୍ତ ସୋର୍ସ ଏଡିଟିଂରେ ପୃଷ୍ଠାଟିରେ {{ଛାଞ୍ଚର ନାମ}}
ଲେଖିବାକୁ ପଡିଥାଏ । ଛାଞ୍ଚ ପୃଷ୍ଠାଟିର ପୁର୍ବାକ୍ଷର "ଛାଞ୍ଚ:" ଲେଖିବା ଅନାବଶ୍ୟକ ଅଟେ । ଯେତେବେଳେ ପୃଷ୍ଠାଟିକୁ ଦେଖିବା ନିମିତ୍ତ କେହି ପାଠକ ଖୋଲନ୍ତି, ଉଇକିପିଡ଼ିଆର ସର୍ଭର ଉକ୍ତ ପୃଷ୍ଠାରେ ଜଡ଼ିତ ସମସ୍ତ ଛାଞ୍ଚର ଲେଖାକୁ ଉଦ୍ଧାର କରି ଛାଞ୍ଚ ଲେଖାଥିବା ଗନ୍ତବ୍ୟ ପୃଷ୍ଠାଟିରେ ବଦଳ କରିଦେଇଥାଏ ।
ଯେତେବେଳେ ଛାଞ୍ଚଟି "ଛାଞ୍ଚ:" ପୁର୍ବାକ୍ଷରଗୁଡ଼ିକ ଛଡ଼ା ଅନ୍ୟ କୌଣସି ପୃଷ୍ଠାରୁ ଅଣାଯାଇଥାଏ, ସେହି ସମୟରେ ସେହି ଅଣାଯାଇଥିବା ପୃଷ୍ଠାର ନାମକୁ ପୁର୍ବାକ୍ଷରରେ ଦେବା ଜରୁରୀ ଅଟେ । ଧରନ୍ତୁ ଆପଣ "ଅମକ ବ୍ୟବହାରକାରୀ:ଛାଞ୍ଚ-୧" ଅନ୍ୟେକ ପୃଷ୍ଠାରେ ଉପଯୋଗ କରିବାକୁ ଚାଁହୁଁଛନ୍ତି, ତେବେ ଖାଲି ଏହିଭଳି {{ଛାଞ୍ଚ-୧}}
ଲେଖିଲେ ତାହା "ଛାଞ୍ଚ:ଛାଞ୍ଚ-୧"କୁ ବୁଝାଇବ, ତେଣୁ ଏହିଭଳି ପରିସ୍ଥିତି ନିମିତ୍ତ {{ଅମକ ବ୍ୟବହାରକାରୀ:ଛାଞ୍ଚ-୧}}
ବ୍ୟବହାର କରିବାକୁ ପଡ଼ିବ ।
ଯଦି ଆପଣ ଏକ ପୃଷ୍ଠାରେ ଏକ ଛାଞ୍ଚ ଉପଯୋଗ କରିବାକୁ ଚାହୁଁଛନ୍ତି ମାତ୍ର ଛାଞ୍ଚଟି ଏପର୍ଯ୍ୟନ୍ତ ତିଆରି ହୋଇନାହିଁ , ତେବେ ଏହା ପୃଷ୍ଠାଟିରେ ନାଲି ଅକ୍ଷରରେ ଦେଖାଯିବ । ତାହା ଉପରେ କ୍ଲିକ କଲେ ଆପଣ ସେହି ଛାଞ୍ଚଟିକୁ ତିଆରି କରିପାରିବେ । ଛାଞ୍ଚଗୁଡ଼ିକ ଉଇକିପିଡ଼ିଆର ଗୋଟିଏ ଭାଷାରୁ ଅନ୍ୟଏକ ଭାଷାକୁ ସିଧାସଳଖ ଉପଯୋଗ କରିହେବ ନାହିଁ । ପ୍ରଥମେ ଛାଞ୍ଚଟିକୁ ଚାହୁଁଥିବା ଭାଷାରେ ଗଠନ କରିବାକୁ ପଡ଼େ । ଅର୍ଥାତ ଇଂରାଜୀ ଉଇକିପିଡ଼ିଆରେ ଧରନ୍ତୁ ଏକ ଛାଞ୍ଚ ବା Template ଅଛି ଯାହା ଓଡ଼ିଆ ଉଇକିପିଡ଼ିଆରେ ନାହିଁ, ପ୍ରଥମେ ସେହି ଛାଞ୍ଚ ପୃଷ୍ଠାଟିକୁ ଓଡ଼ିଆ ଉଇକିପିଡ଼ିଆରେ ତିଆରି କରନ୍ତୁ ତାହାପରେ ଓଡ଼ିଆ ଉଇକିପିଡ଼ିଆରେ ଉପଯୋଗ କରନ୍ତୁ ।
ଟ୍ରାନ୍ସକ୍ଲୁଜନ୍ ଓ ସବଷ୍ଟିଚ୍ୟୁସନ୍ କରିବାର ସମ୍ପୂର୍ଣ୍ଣ ଲିଖନ ଶୈଳୀ
[ସମ୍ପାଦନା]ଉପର ବିଭାଗରେ ଦେଖାଯାଇଥିବା ଟ୍ରାନ୍ସକ୍ଲୁଜନ୍ ଲେଖିବାର ଶୈଳୀକୁ କିଛି ଅଧିକ ଶବ୍ଦ ବା ପାରାମିଟର ଉପଯୋଗକରି ବଢ଼େଇଦିଅଯାଇପାରିବ । ଏହାର ଲିଖନ ଶୈଳୀ ହେଲା:-
{{ଛାଞ୍ଚର ନାମ|ପାରାମିଟର|ପାରାମିଟର|...}}
ଯେଉଁଠି ପ୍ରତ୍ୟେକ ପାରାମିଟର ଜାଗାରେ ଦୁଇ ପ୍ରକାର ଶବ୍ଦ ରହିପାରେ ।
- ନାମବିହୀନ ପାରାମିଟର ବା ସିଧା ସଳଖ ମୂଲ୍ୟ (ଏଠାରେ "ପ୍ରଥମ", "ଦ୍ଵିତୀୟ", ଇତ୍ୟାଦି ଶବ୍ଦ "୧", "୨" ଇତ୍ୟାଦିରେ ଆପେ ଆପେ ବଦଳିଯାଏ ) ଓ
- ନାଁଆଯୁକ୍ତ ପାରାମିଟର ବା ନାମ ସହିତ ମୂଲ୍ୟ (ଯେପରି
ନାମ=ମୂଲ୍ୟ
)
ଅଦୃଶ୍ୟ ଅକ୍ଷରଗୁଡ଼ିକ (ଯଥା ସ୍ପେସ, ଟ୍ୟାବ, ନୂଆ ଧାଡ଼ି ଚିହ୍ନ ଇତ୍ୟାଦି) ନାମଯୁକ୍ତ ପାରାମିଟରର ଆରମ୍ଭ ଏବଂ ଶେଷରୁ ଆପେ ଆପେ କାଢିଦିଆଯାଏ, କିନ୍ତୁ ମଝିରୁ କଢ଼ାହୁଏ ନାହିଁ । ଉଦାହରଣ ସ୍ୱରୂପ {{ ... | ମୋପାରାମିଟର = ଏହା ଗୋଟିଏ ପରୀକ୍ଷା}}
ଯାହା {{ ... |ମୋପାରାମିଟର=ଏହା ଗୋଟିଏ ପରୀକ୍ଷା}}
. ମଧ୍ୟ ସେଇୟା । କିନ୍ତୁ ନାମବିହୀନ ପାରାମିଟରରେ ଏହି ସବୁ ଅଦୃଶ୍ୟ ଅକ୍ଷରଗୁଡ଼ିକୁ କଢ଼ାଯାଏ ନାହିଁ ।
ଛାଞ୍ଚଟିକୁ କେଉଁ ପାରାମିଟର ପଠାହେବ ବା କିପରି ତାହାର ନାମକରଣ ହେବ ସମ୍ପୂର୍ଣ ରୂପେ ଛାଞ୍ଚଟି କିପରି ଲେଖାଯାଇଛି ତାହା ଉପରେ ନିର୍ଭର କରୁଛି । ନାମଯୁକ୍ତ ପାରାମିଟର ଯେକୌଣସି କ୍ରମରେ ଲେଖାଯାଇପାରେ । ତ୍ରୁଟିଯୁକ୍ତ ନାମକୁ ହେଲା କରାଯାଇଥାଏ ; ପୂର୍ବରୁ ତିଆରି ହୋଇନଥିବା ପାରାମିଟରକୁ ଏକ ପୂର୍ବନିର୍ଦ୍ଧାରିତ ନିଶ୍ଚିତ ମୂଲ୍ୟ ପ୍ରଦାନ କରାଯାଇଥାଏ । ଯଦି ଗୋଟିଏ ପାରାମିଟର ଏକରୁ ଅଧିକଥର ଲେଖାଯାଇଛି ତେବେ ସବୁଠାରୁ ଶେଷରେ ଲେଖାଯାଇଥିବା ତଥ୍ୟକୁହିଁ ବିଚାରକୁ ନିଆଯିବ ।
ଗୋଟିଏ ପାରାମିଟରର ମୂଲ୍ୟ ଖାଲି ମଧ୍ୟ ହୋଇପାରେ (ପାଇପ ବା ସମାନ ଚିହ୍ନପରେ ପୁଣିଥରେ ସମାନ ପାଇଁ ବା ସମାନ ଚିହ୍ନ ବା ବନ୍ଧନୀ ବନ୍ଦ ହେବ ଚିହ୍ନ) । ଏହା ଗୋଟିଏ ପରମିତ୍ରକୁ ଆଦୋୖ ତିଆରି ନକରିବାଠାରୁ ଅଲଗା ଅଟେ (ହେଲେ ଛାଞ୍ଚଗୁଡିକୁ ଏଭଳି ତିଆରି କରାଯାଇଥାଏ ଯାହା ଉଭୟ କ୍ଷେତ୍ରରେ ସମାନ ଭାବରେ କାମ କରେ) ।
If a template is to be substituted in the wikitext rather than transcluded, add the modifier subst:
after the initial pair of braces, as in {{subst:afd}}
. Parameters can be added as above. (If substituting a page from mainspace, the word "subst" must be followed by two colons.)
Template names are exactly like other page names: case-sensitive except for the first letter, with spaces indistinguishable from underscores. If the symbol # (normally used to link to a section of a page) appears in a transclusion, then it and any characters that follow it are ignored. If the page name used for transclusion is a redirect, the redirect target will be transcluded instead – this means that alternative names can be created for templates.
Notice that the same double-brace syntax is used for many MediaWiki variables and parser functions (see Help:Magic words). For example, the code {{NAMESPACE}}
may look like a template call, but it is actually a variable whose value is the namespace prefix of the current page.
Basic template usage examples
[ସମ୍ପାଦନା](If you wish to experiment with any of these, please use the template sandbox.)
An example of a very simple template can be found at Template:Km2. Click "View source" on that template page to see the template code (its wikitext). The "active" part of that code, called the expansion of the template, is [[Square kilometre|km<sup>2</sup>]]
. (The remainder of the wikitext is enclosed between <noinclude>...</noinclude> tags, which means that it is displayed on the template page itself, but will not be included along with the template.)
To transclude the above template onto another page (e.g. Wikipedia:Sandbox), type {{km2}}
(or {{Km2}}
– the case of the first letter is not significant) somewhere into the wikitext of the target page, and save it. The page will be displayed as if the template call were replaced by the expansion of the template, i.e. as if the wikitext contained [[Square kilometre|km<sup>2</sup>]]
at that point. The displayed page will therefore contain the linked text "km2".
For example, type Areas of 100 {{km2}} to 200 {{km2}}
, and you will see "Areas of 100 km2 to 200 km2". You can use templates without knowing the details of their code – you only need to remember what result they produce (this is usually described on the template page).
Another way to use this template is to substitute it. If you type Areas of 100 {{subst:km2}} to 200 {{subst:km2}}
and save the page, you will again see "Areas of 100 km2 to 200 km2" However this time, if you look again at the saved wikitext, you will see that the template calls really were replaced by the expansion of the template when you saved the page. The link between the output text and the template is now broken, and the output will not be affected by changes which might be made to the template at some future time (as it would be in the case of transclusion).
Examples with parameters
[ସମ୍ପାଦନା]An example of a template that takes parameters is Template:For. Type {{for|the card game|Contract bridge}}
in the sandbox to produce the following text:
This usage takes two unnamed parameters, but the same template can also be used with different numbers of parameters to give slightly different results, as explained in the documentation on the template page. Note in particular the usage with an empty parameter: {{for||USE1|USE2}}
– here the consecutive pipes mean that the first parameter passed to the template is the empty string.
Other templates, particularly more complex ones, take named parameters (or a mixture of named and unnamed ones). A simple example is Template:Payoff matrix, used to generate a 2-by-2 grid. Type:
{{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }}
ଛାଞ୍ଚ:Payoff matrix to produce the grid you can see on the right.
See the template page for more possibilities. Notice that the template is used here without defining all its possible parameters – undefined parameters are given default values.
The spaces around the equal signs and before and after the parameters are used only for clarity – they are not needed, and are ignored when the template is evaluated (although this is not the case with unnamed parameters). However parameter names are fully case sensitive – for example, it is not possible to replace "DR" by "dr" or "Dr" in the above example. Parameters with names that are not used by the template are simply ignored.
Usage hints and workarounds
[ସମ୍ପାଦନା]The following points may be worth noting when using templates:
- An unnamed parameter cannot contain an ordinary equals sign, as this would be interpreted as setting off a named parameter. (This does not apply if the equals sign comes within another template call or other item which the parser handles separately.) To pass an equals sign in an unnamed parameter (for example in a URL with key/value pairs), replace the equals sign with the special template
{{=}}
, which returns an equals sign that will not be specially interpreted. Another method is to replace the unnamed parameter (and any subsequent unnamed parameters) with named parameters – the first unnamed parameter is equivalent to a named parameter with the name "1", and so on. So to call template {{done}} with the parameter "a=b", type either{{done|a{{=}}b}}
or{{done|1=a=b}}
. - Similarly, it is not possible to use an ordinary pipe character | in template parameters, as it will be interpreted as a separator. (Again, this does not apply if it comes within another separately parsed item, such as a piped wikilink.) This time the problem can be solved by using the special template
{{!}}
in place of the pipe, or (if the pipe is not intended to be parsed specially at a higher level) using the HTML entity |. - Remember that whitespace characters (spaces, tabs, carriage returns and line feeds) are not automatically stripped from the start and end of unnamed parameters (as they are from named parameters). Including such characters (or any other non-visible characters in any parameters) may in some cases affect the template's behaviour in unexpected ways. (Template designers can use {{StripWhitespace}} to remove unwanted whitespace in unnamed parameters.)
- In documentation and discussions it is often convenient to be able to produce the template call syntax, with a link to the template in question, but without actually calling the template. This can be done easily using the "{{tl}}" template (the template link template). For example, using the text "{{tl|tc}}" produces "{{tc}}". There is an extended version, {{tlx}}, which also supports parameters.
- When a template is changed (when the template or one of its subtemplates is edited), the change will be reflected on all pages on which the template is transcluded. However the change may not become visible on all pages immediately – a previously cached version of a page, based on the previous version of the template, may continue to be displayed for some time. Use the purge function to force a page to be displayed using the latest versions of templates. (This includes the template page itself, if it contains usage examples.)
- When viewing old versions of pages, remember that templates will be transcluded as they are now, not necessarily as they were when the old page version was active.
- To list all pages onto which a template is transcluded, use What links here on the template page. (This will not include pages where the template has been substituted.)
- To get a list of templates transcluded on a page, click "Edit", and find the list below the edit window. This list also includes the sub-templates used by the templates that are directly transcluded. To get such a list for a page section, an old version of the page, or your newly edited version prior to saving, click "Show preview" on the appropriate edit page. (For an old version, the subtemplate tree will be constructed according to the templates' current state.)
Creating and editing templates
[ସମ୍ପାଦନା]Templates are created and edited in much the same way as any other page: choose an appropriate name, navigate to that page, then click the Edit tab or create a new page as needed. As mentioned above, templates are normally placed in the Template namespace, though templates intended for your own personal use or for experimentation can be created in your own user space. Anything that can be included on a normal page or article can be included on a template, including other templates (called subtemplates). Templates often make use of programming features – parameters, parser functions and other magic words – which allow the transcluded content to vary depending on context. There are also special tags to control which information is transcluded and which is not.
Before creating a template, do a quick search for existing templates (e.g. by exploring Category:Wikipedia templates) to see if there's already a template that does what you want, or a similar template whose code can be copied and modified (or left in place and expanded). Look for generic templates on which the new template can be based (for example, navbox templates can be easily created by calling the generic Template:Navbox).
There is no hard rule about what name to choose for a template – make it short but reasonably descriptive. If similar templates exist, try to follow the a consistent naming pattern. Templates can be renamed without breaking existing transclusions, provided a redirect to the new template name is left behind.
Be extremely careful when editing existing templates – changes made can affect a large number of pages, often in ways you might not expect. For this reason many high-use templates are protected against editing except by administrators (other editors can propose changes on the talk page). Some templates offer a sandbox and test cases for experimentation.
To propose the deletion of unused or inappropriate templates, or other changes in the way particular templates are used, go to Templates for discussion (TfD).
Handling parameters
[ସମ୍ପାଦନା]The values of the parameters which can be fed to a template are represented in the template code by items enclosed between triple braces:
- the code
{{{xxx}}}
will be replaced by the value of the parameter named xxx - the codes
{{{1}}}
,{{{2}}}
etc. will be replaced by the first, second etc. unnamed parameter (or the value of a parameter named 1, 2, etc.)
If a parameter is not assigned a value, then the above replacements will not take place – the form "{{{xxx}}}" will remain as the effective value of the parameter. To change this behaviour, define default values using the pipe syntax. For example, {{{1|unknown}}}
will be replaced by the first unnamed parameter if there is one, or otherwise by the text "unknown".
Parameters do not get expanded when they are inside nowiki tags or XML-style extension tags. Thus, the following will not work within a template - <myextension xparam={{{tparam}}}> ... </myextension> - because the parameter is not expanded.
Because of the multiple uses of double-brace and triple-brace syntax, expressions can sometimes be ambiguous. It may be helpful or necessary to include spaces to resolve such ambiguity, for example by writing {{ {{{xxx}}} }}
or {{{ {{xxx}} }}}
, rather than typing five consecutive braces. However, watch out for unwanted whitespace appearing in template expansions.
System variables and conditional logic
[ସମ୍ପାଦନା]Template code often makes use of the variables and parser functions described at Help:Magic words, in order to make the template's behaviour depend on the environment (such as the current time or namespace) or on the parameter values which are passed to it. They can also be used for arithmetical calculations. Notice that full string manipulation is not available (although templates have been created which provide such functionality, though very inefficiently and imperfectly), nor are certain standard programming features such as loops and variable assignment.
Some of the most often used variables and functions are listed below. For more, see Help:Magic words, and the fuller documentation at the MediaWiki pages mw:Help:Magic words and mw:Help:Extension:ParserFunctions.
Description | Text Entered | Result |
---|---|---|
Uppercasing text | {{uc: Heavens to BETSY! }} | HEAVENS TO BETSY! |
Lowercasing text | {{lc: Heavens to BETSY! }} | heavens to betsy! |
Getting a namespace name | {{NS: 1 }} | ଆଲୋଚନା |
Getting a wikipedia URL | {{fullurl: pagename }} | //or.wikipedia.org/wiki/Pagename |
The parserFunctions extension gives more programming-oriented parser functions.
Description | Text Entered | Result |
---|---|---|
Testing between options | {{#ifeq: yes | yes | Hooray...! | Darn...! }} {{#ifeq: yes | no | Hooray...! | Darn...! }} |
Hooray...! Darn...! |
Testing if a parameter is set | {{#if: {{{param|}}} | Hooray...! | Darn...! }} | Darn...! |
making a calculation | {{#expr: ( 27 * 46 / pi ) round 2 }} | 395.34 |
Description | Text Entered | Result (for this help page) |
---|---|---|
Page names | {{PAGENAME}} {{FULLPAGENAME}} |
ଛାଞ୍ଚ ସହଯୋଗ:ଛାଞ୍ଚ |
Name of the current namespace | {{NAMESPACE}} | ସହଯୋଗ |
Number of registered users | {{NUMBEROFUSERS}} | ୩୭,୫୮୯ |
Number of pages in a given category | {{PAGESINCATEGORY:"Weird Al" Yankovic albums}} | ୦ |
Current software version | {{CURRENTVERSION}} | 1.44.0-wmf.1 (fbc8c4f) |
Timestamp of last revision | {{REVISIONTIMESTAMP}} | 20180918141120 |
The PAGENAME and NAMESPACE variables are particularly useful, and frequently used, to change template behavior based on context. For example, if the template transcludes a category link (e.g. cleanup templates, which transclude a link categorizing the page as a page which needs cleanup), it will often check the NAMESPACE variable to make sure that talk pages, user pages, or anywhere else the tag might incidentally be placed do not themselves get categorized as pages needing cleanup.
Nesting templates
[ସମ୍ପାଦନା]Templates may contain other templates – usually called 'nesting'. As the template is processed, the wikitext produced by any nested templates is transcluded into the nesting template, so that the final product is essentially processed from the most deeply nested template out. While fairly straight-forward in application, it involves some noteworthy quirks and tricks.
To pass a parameter value to a nested template, place a parameter tag as the value of one of the nested template's parameters.
- Examples:
- Template:A contains "the quick brown {{B|{{{3}}}}} jumped over...". This takes the value passed to the third positional parameter of Template:A and passes it as the first positional parameter of Template:B, then returns the wikitext produced by B as part of the phrase.
- Template:A contains "the quick brown {{B|waldo={{{3}}}}} jumped over...". As above, except the third positional parameter of Template:A is passed to the named parameter 'waldo' of Template:B.
Template parameters themselves can be chosen conditionally.
- Example:
- Template:A contains "the quick brown {{B|{{{3}}}=fox}} jumped over...". Template:A passes the word 'fox' to a parameter of Template:B that's named in A's third positional parameter.
A template can call itself, but will stop after one iteration to prevent an infinite loop.
When a nested template contains unmatched curled-brackets – as in {{lb}} – the unmatched brackets are treated as text during processing, and do not affect the parsing of brackets in the nesting template. If the nested template is substituted, however, the substitution is processed first, and this will change how braces are parsed in the nesting template. This has little practical use, but can occasionally introduce unexpected errors.
See the help:advanced templates and meta:Help:Recursive conversion of wikitext for more information. These pages also contain information on unusual calls such as {{template {{{parameter|}}} }}.
Noinclude, includeonly, and onlyinclude
[ସମ୍ପାଦନା]By default, when a template is transcluded (or substituted), the entire wikitext (code) of the template page gets included in that of the target page. However it is possible to modify that behaviour, using tags that specify which parts of the template code are to be included. This makes it possible to avoid transcluding information intended for display only on the template page itself, such as the template's documentation, categories and interwiki links. It is also possible to have parts of the code be transcluded, but not be processed on the template page itself (e.g. categories to be applied to the target pages which do not apply to the template). The tags are as follows
<noinclude>...</noinclude>
– the text between the noinclude tags will not be included when the template is transcluded (substituted)<includeonly>...</includeonly>
– the text between the includeonly tags will be transcluded (substituted), but will not be processed on the template's own page<onlyinclude>...</onlyinclude> (not often used) – specifies that nothing on the page except what appears betweeen the onlyinclude tags will be transcluded (substituted)
Perhaps the most common issue with the use of these blocks is unwanted spaces or lines. It is important to remember that the effect of these tags ends immediately after the last angle bracket, not on the next line or with the next visible character.
These tags can be nested inside each other, though (for a given page) this really only applies to the 'onlyinclude' tag; nesting 'includeonly' and 'noinclude' tags is fairly pointless. Be careful not to split the tags, however. Constructions like this <onlyinclude>abc<includeonly>def</onlyinclude>ghi</includeonly> will not work as expected. Use the 'first opened, last closed' rule that is standard for XML.
Problems and workarounds
[ସମ୍ପାଦନା]
- If the first included character of a template is one of the Wiki markup characters :;*#, then it is processed as though it is at the beginning of a line (even when the template tag is not). This allows the creation of various kinds of lists in templates where the template may not always be in the correct place for a list. To avoid this effect use <nowiki>#</nowiki> or a numeric character reference (ଛାଞ୍ଚ:Mlw) or HTML entity such as : for a colon. This NCR is also useful in conjunction with definition lists.
- For issues involving the substitution of templates (for example, how to control whether subtemplates are substituted as well when the parent template is substituted), see Help:Substitution.
- The template {{StripWhitespace}} can be used to strip any initial or final whitespace from unnamed parameter values, if this would cause problems (named parameter values are automatically stripped in this way).
- For debugging templates the following techniques are sometimes helpful:
- using 'subst:' - substituting a template (rather than transcluding it) can show more clearly what is happening when the template is transcluded.
- using 'msgnw:' - this keyword (short for "message, nowiki") transcludes the wikitext of the template page, more or less, rather than the processed contents. it is not perfect: lists are rendered, comments are removed, and single newlines are replaced with spaces (which is particularly confounding when transcluding wikitext tables).
- using Special:ExpandTemplates to see the full recursive expansion of one or more templates.
- To protect server resources and avoid infinite loops, the parser imposes certain limits on the depth of nesting of transclusions and on the page size with expanded templates. This may cause pages to break when using very complex templates, particularly if there are multiple such templates on the same page. For more information, see Template limits. (A page's overall load on the server can be checked by examining the generated HTML for a page and looking for the "NewPP limit report" comments.)
- Do not use
=
wikimarkup to create section headers within a template which is intended for use in article space — this will create an [edit] link that when transcluded will confusingly open the template for editing.
Documentation and categories
[ସମ୍ପାଦନା]
Categorizing your template and documenting its proper usage will make it easier for other editors to find and use. For detailed advice, see Wikipedia:Template documentation.
Documentation for users, together with the template's categories and interwiki links, is normally placed after the template code, inside "noinclude" tags. It is normally necessary to put the opening "noinclude" tag immediately after the end of the code, with no intervening spaces or newlines, to avoid transcluding unwanted whitespace.
In the case of complex templates, the documentation (together with categories and wikilinks) is often kept on a separate subpage of the template page (named "Template:XXX/doc"). This also applies to many protected templates (to allow the information to be edited by non-administrators). This is achieved by placing the {{Documentation}} template after the main template code (within "noinclude" tags). If the "/doc" subpage does not exist, a link will then appear enabling it to be created.
Some templates contain category definitions in their transcluded code, i.e. they are intended to place the target pages in particular categories. This is often done with maintenance categories (placing articles into ordinary content categories in this way is discouraged). When doing this, it may be necessary to use "includeonly" tags to keep the template itself out of the category. The template should also be designed to suppress categorization in the case of demonstration uses – see Category suppression in templates.
See also
[ସମ୍ପାଦନା]
Help pages
Manual pages
Special pages
Other pages not for direct viewing
- m:Help:Template
- meta:User:Happy-melon/Templates
- mw:Help:Templates
- m:Help:Advanced templates
- Introductions:
- Help:Calculation
- Wikipedia:List of templates
- Help:Magic words
- mw:Help:Magic words
- mw:Help:Extension:ParserFunctions
- m:Help:Parameter default
- Help:Substitution
- Wikipedia:Template documentation
- Wikipedia:Template namespace
- Wikipedia:Template limits
- Wikipedia:Template test cases
- Wikipedia:WikiProject Templates
- interwiki transclusion
- mw:Extension:ExpandTemplates
- mw:Extension:Labeled Section Transclusion - transclusion of part of a page
- #arg: - instead of including a page for given parameter values, this allows linking to a page for given parameter values. Syntax for parameter use: {{arg:parameter name|default}}. Syntax for linking: external link style with "¶meter name=parameter value" added to the URL.
- mw:Manual:Parser.php
- Special:Mostlinkedtemplates - shows the number of pages in which each template is transcluded, not counting transclusions through redirects
- Special:Unusedtemplates - templates which are not transcluded (however, they may be used for substitution)
- Special:Allpages (namespace 10) all templates on this server
- Special:ExpandTemplates
- multilingual portal pages, see meta:www
- CSS and JS pages, see Help:User style
- pages in the MediaWiki namespace, see Help:System message
- Wikipedia:Book sources, used by Special:Booksources
- m:Spam blacklist
Notes
[ସମ୍ପାଦନା]
- ↑ Namespaces from which transclusion is not allowed are specified on a wiki by the variable $wgNonincludableNamespaces