সহায়:সাঁচ: বিভিন্ন সংশোধনসমূহৰ মাজৰ পাৰ্থক্য

Bot: Migrating 1 langlinks, now provided by Wikidata on d:q4168710
Bot: Replace deprecated <source> tag and "enclose" parameter; কসমেটিক পরিবর্তন
1 নং শাৰী:
{{Wiki markup}}
{{shortcut|HELP:T|Wikipedia:TEMPLATE}}
:''To find lists of commonly used templates, see [[Wikipediaৱিকিপিডিয়া:Template messages]].''
 
A '''template''' is a Wikipedia page created to be included in other pages. Templates usually contain repetitive material that might need to show up on any number of articles or pages. They are commonly used for [[Wikipediaৱিকিপিডিয়া:Glossary#Boilerplate text|boilerplate]] messages, standard warnings or notices, [[Helpসহায়:Infobox|infoboxes]], [[WPৱিকিপিডিয়া:Navbox|navigational boxes]] and similar purposes.
 
The most common method of inclusion is called [[Wikipediaৱিকিপিডিয়া:Transclusion|transclusion]], where the [[WPৱিকিপিডিয়া:wikitext|wikitext]] of the target page contains a reference to the template, using the <code><nowiki>{{Template name}}</nowiki></code> syntax. Another method is [[Helpসহায়:Substitution|substitution]], where the content of the template is copied into the wikitext of the target page, just once, when it is saved.
 
For a brief introduction to the subject, see ''[[Helpসহায়:A quick guide to templates|A quick guide to templates]]''.
 
== General ==
Most templates are pages in the [[WPৱিকিপিডিয়া:Template namespace|Template namespace]], which means that they have titles in the form "Template:''XXX''". It is possible, however, to transclude and substitute from any namespace,<ref>Namespaces from which transclusion is not allowed are specified on a wiki by the variable [[mw:Manual:$wgNonincludableNamespaces|$wgNonincludableNamespaces]]</ref> and so some template pages are placed in other namespaces, such as the [[WPৱিকিপিডিয়া:User namespace|User namespace]]. Template pages have associated [[WPৱিকিপিডিয়া:talk page|talk pages]].
 
Templates can contain any desired [[wp:wikitext|wikitext]], including calls to other templates. They have some limited programming capacities: customizable values (called [[#Parameters|parameters]]), calculation and branchings (using [[Helpসহায়:Parser functions|parser functions]]), and access to wiki-specific variables ([[Helpসহায়:Magic words|magic words]]), such as dates, times, and page names. They may also contain tags which define which parts of the wikitext are to be included when the template is transcluded or substituted. This means that the appearance of the template page itself need not be the same as that of the transcluded content (for example, it can contain documentation, categories, etc. for the template).
 
'''How to do it:''' To transclude a template to an article or page, type <code><nowiki>{{template name}}</nowiki></code> in the wikitext at the place where the template is to appear. The prefix "Template:" need not be included, and an initial capital is not necessary.
 
Templates stored in other namespaces are transcluded in the same way, except that the namespace prefix, such as "User:", must be included. To transclude a page in [[WPৱিকিপিডিয়া:mainspace|mainspace]], precede its title with a colon, as, for example, <code><nowiki>{{:Page name}}</nowiki></code>.
 
'''Note:''' Attempting to transclude a template that does not exist produces a [[wp:redlink|red link]], just like linking to any other nonexistent page. Following the link allows one to create that particular template. It is not possible to transclude pages between projects (such as different language Wikipedias)&nbsp;— to use a template on another language project, a copy of the template must be created in that project.
 
== Full syntax for transcluding and substituting ==
The basic transclusion syntax given above can be extended by the addition of [[parameter]]s, which are used to control the template's output. The syntax for this is
* <code><nowiki>{{template name|parameter|parameter|...}}</nowiki></code>
31 নং শাৰী:
The value of a parameter can be the empty string (pipe or equals sign followed immediately by the next pipe or the closing braces). This is different from leaving the parameter undefined (although templates are often coded so as to behave the same in both cases).
 
If a template is to be [[Helpসহায়:Substitution|substituted]] in the wikitext rather than [[WPৱিকিপিডিয়া:transclusion|transcluded]], add the modifier <code>subst:</code> after the initial pair of braces, as in <code><nowiki>{{subst:afd}}</nowiki></code>. 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 [[Helpসহায়:Page name|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 [[WPৱিকিপিডিয়া:redirect|redirect]], the redirect target will be transcluded instead&nbsp;— 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 <code><nowiki>{{NAMESPACE}}</nowiki></code> 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সাঁচ:Template sandbox|template sandbox]].)
 
An example of a very simple template can be found at [[Templateসাঁচ:Lambda]], which places the lambda symbol, λ. Click the "Edit" tab on that template page to see the template code (its wikitext). The "active" part of that code, called the ''expansion'' of the template, is <code>&amp;lambda;</code>. (The remainder of the wikitext is enclosed between <nowiki><noinclude>...</noinclude></nowiki> 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. in the [[Wikipediaৱিকিপিডিয়া:Sandbox]]), type <code><nowiki>{{lambda}}</nowiki></code> (or <code><nowiki>{{Lambda}}</nowiki></code>&nbsp;— 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 <code>&amp;lambda;</code> at that point. The displayed page will therefore contain the text "λ".
 
For example, type "<code>The 11th letter of the Greek alphabet is the lambda (<nowiki>{{lambda}}</nowiki>)</code>" and you will see "The 11th letter of the Greek alphabet is the lambda ({{lambda}})". You can use templates without knowing the details of their code&nbsp;— 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 [[Helpসহায়:Substitution|substitute]] it. If you type "<code>The 11th letter of the Greek alphabet is the lambda (<nowiki>{{subst:lambda}}</nowiki>)</code>" and save the page, you will again see ""<code>The 11th letter of the Greek alphabet is the lambda (λ)</code>". 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 ===
{{anchor|Parameters}}
An example of a template that takes parameters is [[Templateসাঁচ:For]]. Type <code><nowiki>{{for|the card game|Contract bridge}}</nowiki></code> in the sandbox to produce the following text:
{{for|the card game|Contract bridge}}
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. For example, <code><nowiki>{{For||Latins|Latin (disambiguation)}}</nowiki></code> produces
56 নং শাৰী:
Note in particular the usage with an empty parameter&nbsp;— 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:
:<code><nowiki>{{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }}</nowiki></code>
{{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }}
65 নং শাৰী:
The spaces around the equal signs and before and after the parameters are used only for clarity&nbsp;— 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&nbsp;— 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 {{tlx|{{=}}}}, 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&nbsp;— the first unnamed parameter is equivalent to a named parameter with the name "1", and so on. So to call template {{tl|done}} with the parameter "a=b", type either <code><nowiki>{{done|a{{=}}b}}</nowiki></code> or <code><nowiki>{{done|1=a=b}}</nowiki></code>.
71 নং শাৰী:
* 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 {{tl|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|tl}}" template (the ''template link'' template). For example, using the text "<tt><nowiki>{{tl|tc}}</nowiki></tt>" produces "{{tl|tc}}". There is an extended version, {{tl|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&nbsp;— 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 [[Helpসহায়:Purge|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 [[WPৱিকিপিডিয়া:What links here|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 [[WPৱিকিপিডিয়া:Template namespace|Template namespace]], though templates intended for your own personal use or for experimentation can be created in your own [[WPৱিকিপিডিয়া:user space|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&nbsp;— parameters, parser functions and other [[Helpসহায়:Magic words|magic words]]&nbsp;— 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, [[WPৱিকিপিডিয়া:navbox|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&nbsp;— make it short but reasonably descriptive. If similar templates exist, try to follow 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&nbsp;— changes made can affect a large number of pages, often in ways you might not expect. For this reason many high-use templates are [[WPৱিকিপিডিয়া:protection|protected]] against editing except by [[WPৱিকিপিডিয়া:administrator|administrators]] (other editors can propose changes on the talk page). Some templates offer a sandbox and [[Wikipediaৱিকিপিডিয়া:Template test cases|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 [[WPৱিকিপিডিয়া:Templates for discussion|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 <code><nowiki>{{{xxx}}}</nowiki></code> will be replaced by the value of the parameter named ''xxx''
98 নং শাৰী:
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 <code><nowiki>{{ {{{xxx}}} }}</nowiki></code> or <code><nowiki>{{{ {{xxx}} }}}</nowiki></code>, 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 hereafter. For more, see [[Helpসহায়:Magic words]], and the fuller documentation at the MediaWiki pages [[mw:Help:Magic words]] and [[mw:Help:Extension:ParserFunctions]].
 
{| class="wikitable" style="text-align:center;" width="80%"
139 নং শাৰী:
|{{#if: {{{param|}}} | Hooray...! | Darn...! }}
|-
| [[Helpসহায়:Calculation|Making a calculation (mathematics)]]<br />[area of circle of radius 4, to 3 decimal places]
|<nowiki>{{#expr: ( pi * 4 ^ 2 ) round 3 }}</nowiki>
|{{#expr: ( pi * 4 ^ 2 ) round 3 }}
|-
| [[Helpসহায়:Calculation|Testing the result of a calculation]]<br />[is 1230 even or odd?]
|<nowiki>{{#ifexpr: 1.23E+3 mod 2 | Odd | Even }}</nowiki>
|{{#ifexpr: 1.23E+3 mod 2 | Odd | Even }}
179 নং শাৰী:
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&nbsp;— this is 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 straightforward in application, it involves some noteworthy quirks and tricks.
 
195 নং শাৰী:
When a nested template contains unmatched curled-brackets&nbsp;— as in {{tl|lb}}&nbsp;— 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 <nowiki>{{template {{{parameter|}}} }}</nowiki>.
 
=== 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, [[WPৱিকিপিডিয়া:Category|categories]] and [[WPৱিকিপিডিয়া:interwiki links|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
* <code><nowiki><noinclude>...</noinclude></nowiki></code>&nbsp;— the text between the noinclude tags will not be included when the template is transcluded (substituted)
* <code><nowiki><includeonly>...</includeonly></nowiki></code>&nbsp;— the text between the includeonly tags will be transcluded (substituted), but will not be processed on the template's own page
207 নং শাৰী:
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 <tt><nowiki><onlyinclude>abc<includeonly>def</onlyinclude>ghi</includeonly></nowiki></tt> 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 '''<tt>:;*#</tt>''', 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 <tt>&lt;nowiki&gt;#&lt;/nowiki&gt;</tt> or a numeric character reference ([[Numeric character reference|NCR]]) or HTML entity such as <tt>&amp;#58;</tt> for a colon. This NCR is also useful in conjunction with definition [[Helpসহায়:list|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 {{tl|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:"&nbsp;— substituting a template (rather than transcluding it) can show more clearly what is happening when the template is transcluded.
** using "msgnw:"&nbsp;— 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 [[WPৱিকিপিডিয়া:Template limits|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 <code>=</code> wikimarkup to create section headers within a template which is intended for use in article space&nbsp;— 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 [[WPৱিকিপিডিয়া:interwiki links|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 [[WPৱিকিপিডিয়া:subpage|subpage]] of the template page (named "Template:XXX/doc"). This also applies to many [[WPৱিকিপিডিয়া:protection|protected]] templates (to allow the information to be edited by non-administrators). This is achieved by placing the {{tl|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&nbsp;— see [[WPৱিকিপিডিয়া:CATSUP|Category suppression in templates]].
 
== Expand limits ==
When templates are rendered or expanded to HTML for viewing in your browser, they use memory. This is called the post-expand include size and has a limit of 2,048,000 bytes. This size is included as an invisible comment in the HTML output— use your browser's view source feature to show the raw HTML and search for ''newpp''. The report will look like:
<sourcesyntaxhighlight lang="html4strict">
<!--
NewPP limit report
237 নং শাৰী:
Expensive parser function count: 2/500
-->
</syntaxhighlight>
</source>
 
The example shows that template expansion is using 63k out of 2M of available memory.
 
If too many templates are included on a page, the post-expand include size may exceed the limit. When this happens, templates after the limit will no longer expand and will show as {{red|1=[[Templateসাঁচ:templatename]]}}. Common issues are the inclusion of too many citation templates and/or flag templates. To resolve this, [[Wikipediaৱিকিপিডিয়া:Substitution|subst]] templates, remove templates or split the page.
 
== See also ==
 
{| class="wikitable"
257 নং শাৰী:
* Introductions:
** [[Transclusion]]
** [[Helpসহায়:A quick guide to templates]]
** [[mw:Help:Templates]]
* [[Helpসহায়:Calculation]]
* [[Wikipediaৱিকিপিডিয়া:List of templates]]
* [[Helpসহায়:Magic words]]
* [[mw:Help:Magic words]]
* [[mw:Help:Extension:ParserFunctions]]
* [[m:Help:Parameter default]]<!-- m: -->
* [[Helpসহায়:Substitution]]<!-- maybe portable, test it -->
* [[Wikipediaৱিকিপিডিয়া:Template documentation]]
* [[Wikipediaৱিকিপিডিয়া:Template namespace]]
* [[Wikipediaৱিকিপিডিয়া:Template limits]]
* [[Wikipediaৱিকিপিডিয়া:Template test cases]]
* [[Wikipediaৱিকিপিডিয়া:WikiProject Templates]]
|
* [[mw:Manual:$wgEnableScaryTranscluding|Interwiki transclusion]]
278 নং শাৰী:
* [[mw:Manual:Parser.php]]
|
* [[Specialবিশেষ:Mostlinkedtemplates]]&nbsp;— shows the number of pages in which each template is transcluded, not counting transclusions through redirects
* [[Specialবিশেষ:Unusedtemplates]]&nbsp;— templates which are not transcluded (however, they may be used for substitution)
* [{{fullurl:Special:Allpages|namespace=10}} 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 ==
{{Reflist}}