विकिपीडिया:सहाय्य:प्रगत साचे
Metawikipedia:Help:Advanced templates येथील पानाचे भाषांतर
या पानात ,प्रगत साचांचे तंत्रज्ञान नमुद केले आहे,विशेषतः,साच्यांच्या बदलणार्या नावांचा वापर तसेच साच्यांच्या कार्यकक्षांची नावे इत्यादी. सहाय्य:साचे येथे असणार्या साच्यांचे तंत्रज्ञान वाचकांनी, संपूर्णपणे अवगत करून घ्यावे.यातील काही खाली नमुद केलेली तंत्रे ही मर्यादित स्वरुपाची असु शकतात तर काही अद्ययावत् नसु शकतात ;उदाहरणार्थ: येथील चर्चा केलेली काही (ब्रांचिंग टेक्निक्स) branching techniques[मराठी शब्द सुचवा] यापेक्षा पार्सर क्रिया या जास्त सुटसुटीत असु शकतात.
.This page covers advanced template techniques, in particular the use of variable template names and parameter names in templates. Readers should be thoroughly familiar with the standard template techniques found in Help:Template. Some techniques described below may be outdated or of limited use; for example, ParserFunctions may be more convenient than some of the branching techniques discussed.
सर्वसाधारणपणे,ही तंत्रे पुनर्कृति (रीकर्सिव्ह)recursive[मराठी शब्द सुचवा] (आतुन-बाहेर) पद्धतीच्या साच्यांवर प्रक्रिया करण्यावर अवलंबुन असतात.जेंव्हा एखाद्या साच्यावर प्रक्रिया करण्यात येते,ती साच्याचा संकेतास(कोड) string values (स्ट्रिंग किंमतीत)[मराठी शब्द सुचवा] भाषांतरीत करते. बहुधा, हे सरळ वेब ब्राउजरला सादरीकरणास पाठविले जाते परंतु त्यास 'संकेत'(code) म्हणुनही समजल्या जाउ शकते. दोन महिरपी कंसात (गद्य स्ट्रिंग) text strings[मराठी शब्द सुचवा] बद्ध केल्यावर () साच्यांची नावे किंवा बदल नावे म्हणुनही त्यावर पुनर्प्रक्रिया केल्या जाउ शकते. त्याने, string च्या किंमती बदलल्यामुळे, वेगवेगळे निकाल मिळतात.
In general, these techniques rely on the recursive (inside-out) processing of templates. When a template is processed, it translates template code into string values. These are often sent directly to the web browser for display, but they can be treated as code themselves. By enclosing the text strings in double-curly-brackets ( ), for instance, they can be reprocessed as template names or variable names, producing different results as the string values are changed.
नोंदी:
- हे कागदपत्र सध्या फक्त 'मिडियाविकी' सॉफ्टवेअर मध्ये असलेल्या आवृत्ती १.६ व त्यानंतरच्या आवृत्तीत असलेले घटकच संदर्भित करते.
- This document refers to features currently only available in the Mediawiki software starting with version 1.6 and later.
- "variable" या शब्दाचे या कागदपत्रात दोन उपयोग आहेतः
- ते कधी-कधी 'जादुई शब्द' यासाठी समानार्थी म्हणुनही वापरण्यात येते. ते प्रणाली-स्थित आहेत जे(जसे {{नामविश्व}} साच्यांसारखे वापरले जाउ शकतात.तसे केल्यास,त्या पान कसे आहे त्यावर अवलंबुन सध्या असलेल्या नामविश्वाचे नाव मिळते).
- नाहीतर,ते असे दर्श्विण्यास वापरतात, जे संदर्भ बघुन बदलु शकते.{जसे, "साच्यांची बदलणारी नावे" म्हणजे,साच्यांची ती नावे,जी आमंत्रिल्यावर (कॉल्ड) कार्यकक्षा वा दुसर्या बदलानुसार बदलतील.
- The term "variable" has two uses in this document:
- It is sometimes used as a synonym for magic words, which are system-based variables that can be accessed in the same manner as templates (thus {{NAMESPACE}} will return the name of the current namespace, depending on the page).
- Otherwise, it is used to indicate that something may vary with context (thus, "Variable template names" means that the name of the template being called can change according to parameters or other variables).
- "पर्याय:" हे मानविय पुनर्कृती(manual recursion) वापरल्यास, ट्प्प्याटप्प्याने त्यातील बदल मिळतील,जे एखाद्या दुसर्या साच्यास आमंत्रिल्यावर, त्या विशिष्ट साच्याचे कार्य कसे चालते याचे प्रतिपादन व विश्लेशण दाखविण्यास सहाय्यभूत ठरु शकते.
- Using "subst:" with manual recursion gives a stepwise replacement, useful for analyzing and explaining the working of templates calling other templates. For instance, compare {{{{tctc}} }} (discussed below) with {{{{subst:tctc}} }} on a sandbox page. though both produce the same visible result, the first will will remain as the full code {{{{tctc}} }}, while the second will replace the inner template {{tctc}} with its value, leaving the code {{tc }}. See, e.g., Template talk:Lop.
Variable templates बदलणारे साचे
[संपादन]काही प्रकरणात, एखाद्या साच्यास ,बदल किंवा कार्यकक्षा निस्तरणा बघुन, दुसर्या अनेक साच्यांना आमंत्रित करणे सहाय्यक ठरु शकते. In some cases, it may be useful for a template to call different templates depending on a variable or a passed parameter. This allows a type of branching that can be simpler than Parser functions, though they are generally less versatile.
उदाहरण:
- Using a variable to choose a template -
{{ {{नामविश्व}} }}
- The Magic Word {{नामविश्व}} returns the current namespace, like so: {{नामविश्व}} = विकिपीडिया. The outer brackets then process this result as a template in its own right - in this case साचा :सहाय्य - which produces .
- Using a template to choose a template -
{{{{tctc}} }}
- the template {{Tctc}} contains the text "tc". This text is processed by the outer brackets as Template:tc which contains the word "{{साचा:Tctc }}".
The extra spaces in the above examples are needed: without them, the code is not processed as a template or a magic word, but just as a plain text string like so: {{{{NAMESPACE}}}}.
- Using a variable to choose a template, and passing it a parameter -
{{{{{2}}}x|{{{1}}}}}
- The second parameter passed becomes part of the template name to which the first parameter is passed. In this case
would produce{{2x|{{{1}}}}}
{{{1}}}{{{1}}}
,
would produce{{3x|{{{1}}}}}
{{{1}}}{{{1}}}{{{1}}}
, and etc. Template:Histogram uses this technique repeatedly in{{histogram|X|4|7|3|2|9}}
to produce the following 5 line histogram:
Since there is no convenient way to test substring values (even using parser functions), these techniques work best if the variable template has only a limited number of possible values. For example, the variable {{CURRENTDAYNAME}}
has only seven possible values, so all cases can be handled with seven templates (or fewer, if some are redirects), and the variable {{NAMESPACE}}
currently has 18 possible values. On the other hand, {{CURRENTTIME}}
has 1440 possible values, which would require the creation of 1440 template pages or redirects, which would be impractical. Even with parser functions, all 1440 values would have to be listed (see m:Template:hour (backlinks edit) and m:Template:minute (backlinks edit)). In cases like that, it would be better to construct the template with multiple parameters that each only take a few values, rather than trying to account for all possibilities in a single parameter.
If a template depends on PAGENAME, then the many possible values of PAGENAME may not be a problem. Only the pagenames of the pages that call the template apply, and these can be limited to a small, enumerable set.
Templates passed as parameters
[संपादन]Templates can be passed as parameters to other templates. This can mean either that the template is evaluated and the result is passed as a parameter or that the template name is passed and evaluated as part of the other template.
- Passing a template result - {{3x|{{tc}}}}
- Template:3x contains {{{1}}}{{{1}}}{{{1}}}. {{3x|{{tc}}}} first evaluates {{tc}} (which yields the word in), and passes that to template {{3x}}, to give साचा:3x
- Passing a template result recursively - {{3x|{{5x|{{tc}}}}}}
- Just as above except {{tc}} (in) is first passed to {{5x}} and the result of that is passed to {{3x}}, to give साचा:3x.
- Passing a template name -
{{tt|t|V}}
- Template:tt -
{{{{{1}}}|a{{{2}}}b{{{2}}}c{{{2}}}d}}
- takes the value V (passed as the second parameter) and produces aVbVcVd. This value is then passed to template:t (which was passed by name as the first parameter), producing "साचा:Tt"
Variable parameters
[संपादन]A parameter name in a template can be a variable. This is useful if you want the behavior of a template to change based on the information that is provided to it.
Choosing parameters contextually - {{t pnd|parameter name}}
Template:t p contains
{{{capital}}} is the capital of {{{country}}}
, with two parameters - "capital" and "country". साचा:Timc can be used to select which parameter is used in a particular case. Thus:
याने... हे मिळते {{t pnd|राजधानी}}
साचा:T pnd {{t pnd|देश}}
साचा:T pnd {{t pnd|ईतर काही}}
साचा:T pnd This applies to integer parameters as well, since integer parameters can be specified using the "#=" notation. Passing the integer value N to {{t pnd}} as its parameter will make it look for the Nth unnamed parameter.
- Parameter name from another parameter in the same template -
{{tvv|parameter=foo|foo=bar}}
- Using Template:tvv, which contains {{{{{{parameter}}}}}}, the code
साचा:Tvv
will first set the parameter named "foo" to the value "bar", and then set the parameter named "parameter" to the value of foo, yielding साचा:Tvv. The order in which the parameters appear in the code does not matter, but the technique cannot be applied multiple times—e.g.,{{foo}}
—and it may fail if substituted rather than transcoded.
The following branching methods are generally obsolete; Parser Functions give easier forms of control. However, they may be useful in particular situations, and point out some unintuitive features of template behavior.
- Blank parameter branch -
{{t pdc|abc}}
,{{t pdc}}
,{{t pdc}}
- Template {{tts}} contains साचा:Tcw, which takes a parameter with a blank name (i.e.,
{{tts}}
) and processes it as a template, but ignores any other parameter. Template:T pdc, which contains साचा:Tcw, will produce साचा:T pdc in the first and last cases,{{t pdc}}
will give साचा:T pdc because a blank parameter name is explicitly passed. - If-defined branches -
{{{test{{{test|}}}|{{{then}}}}}}
- If no value is passed for the parameter test, then {{{test{{{test|}}}|{{{then}}}}}} resolves to {{{test|{{{then}}}}}} and returns a blank entry (since test is defined as blank). If the parameter "test" is assigned the value "boo", however, {{{test{{{test|}}}|{{{then}}}}}} resolves to {{{testboo|{{{then}}}}}}, and so long as no parameter "testboo" exists, then this will return the value of the parameter "then".
Variable variables (Magic Words)
[संपादन]Variables (Magic Words) names can also be generated as variables.
- Magic word generated as a variable -
{{t curr}}
- साचा:Timc gives the text {{CURRENTसाचा:T day}} without parameters, since it defaults to {{CURRENTDAY}}, but
{{t curr|DAYNAME}}
gives साचा:T curr while{{t curr|MONTHNAME}}
gives साचा:T curr. Any magic word that begins with "CURRENT" can be accessed this way.
- Namespace generated as a variable -
{{ns:{{{1}}}}}
- In Template:Namespace, which contains {{#switch:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}
| {{ns:0}}=लेख | {{ns:1}}=चर्चा पान | {{ns:2}}=सदस्य पान | {{ns:3}}=सदस्य चर्चा पान | {{ns:4}}=विकिपीडिया | {{ns:5}}=विकोपीडिया चर्चा | {{ns:6}}=चित्र | {{ns:7}}=चित्र चर्चा पान | {{ns:8}}=मिडियाविकी | {{ns:9}}=मिडियाविकी चर्चा पान | {{ns:10}}=साचा | {{ns:11}}=साचा चर्चा पान | {{ns:12}}=साहाय्य पान | {{ns:13}}=साहाय्य चर्चा पान | {{ns:14}}=वर्ग | {{ns:15}}=वर्ग चर्चा पान | {{ns:100}}=दालन | {{ns:101}}=दालन चर्चा | {{ns:828}}=विभाग | {{ns:829}}=विभाग चर्चा | {{TALKSPACE}}=चर्चा पान | page}}<noinclude> {{documentation}} [[वर्ग:विकिपीडिया प्रारुपण व क्रिया साचे|{{PAGENAME}}]] </noinclude>, the last use of the parameter evaluates to a number #, and the entire phrase ns:# is evaluated as a template. Thus, {{namespace|4}} gives लेख, where Meta is the name of Namespace 4.
External examples
[संपादन]- VARIABLE MAGIC WORDS
- Template:H:h and Template:H:f (see edit pages, MediaWiki help policy, and list)
- Template:Nsn - namespace number (see also below)
- Template:Gns - generic namespace name, useful for linking to the corresponding page on another project
- de:MediaWiki:Newarticletext and de:MediaWiki:Noarticletext (see edit pages and list)
- w:en:Template:H:f - for project-specific content on all help pages of the English Wikipedia (requires a blank template on all pages that do not have this content)
- VARIABLE PARAMETER NAMES
- en:Template:Reg polyhedra db (backlinks edit), which contains a 2D array in the form {{{{{1}}}|{{{2}}}|1-1=a11|..|m-n=amn}}. The first parameter is the name of a template that provides a particular selection and presentation of a selected row of the array, e.g., en:Template:Reg polyhedron stat table (backlinks edit), the second parameter (which is the first parameter of the latter template) specifies the row. The latter template references element j of the row concerned by a tag of the form {{{{{{1}}}-j}}}
See also
[संपादन]- ParserFunctions (Syntax for #if:, #expr: etc.)
- Meta talk:Templates for translating language names
- Help:Array