বিষয়বস্তুতে চলুন

টেমপ্লেট:Wrapper template

উইকিপিডিয়া, মুক্ত বিশ্বকোষ থেকে

Wrapper templates are outer templates which wrap around simpler inner templates, to greatly extend the basic functionality of the inner templates. The concept is to structure the underlying, inner templates to be used as utility tools by various outer, wrapper templates.

Experience has shown that, when the underlying templates have been restructured with a full set of options to be used, then numerous variations of wrapper templates have been created to extend template functionality with a broad variety of new features.

Wrapper templates can be useful for consolidation, as they allow templates to build off of each other, whereas copying and pasting templates can make them harder to maintain.

A simple example

[সম্পাদনা]

The function of Template:Exams is to place a box on one's userpage stating that one is taking a wikibreak to focus on exams. A more general template for wikibreaks, Template:Wikibreak, already exists, so rather than duplicating it, {{Exams}} just consists of a call of {{Wikibreak}} with some parameters specified, such as an image of books rather than the default image of a sunset.

An example with substitution

[সম্পাদনা]

Template:Don't ping inserts a message on a talk page that one is following the page and doesn't need to be pinged in replies. It calls Template:Please ping with the no parameter specified. This gets a little trickier because {{Don't ping}} may be substituted. To address this, the actual code used is {{safesubst:<noinclude/>Please ping|no}}.

A more complex example

[সম্পাদনা]

One of the most successful applications, of using wrapper templates, has been in extending the features of Template:Convert, which originally could only handle single-value or 2-value ranges of measurement conversions as simple numerals in text. However, once the inner subtemplates of {Convert} were modified to optionally display only the raw values, unit names, or unit symbols, then many wrapper templates were created to handle complex ranges of 4 amounts, with numbers formatted as gapped-digit numerals or spelled-out words:

  • Template:Convert – the original converter for single or 2-amount ranges
  • {{Convert/2}} – converter for any range, beyond limits of Convert
  • {{Convert/3}} – converter for 3-value ranges, not allowed by {Convert} until 2014
  • {{Convert/4}} – converter for 4-value ranges, with free-form text far beyond {Convert}

Template {Convert/4} could be used to convert 4 amounts at once, as a single thought, such as showing common sizes of lumber for 2 boards at once, or perhaps 2 bedrooms at once:

  • {{convert/4 |2|x|4|or wide|1|x|6|in|cm}} ⊟ {{convert/4|2|x|4|or wide|1|x|6|in|cm}}
  • {{convert/4 |15|x|18|with 2nd bedroom|12|x|15|ft|m}} ⊟ {{convert/4|15|x|18|with 2nd bedroom|12|x|15|ft|m}}

Meanwhile, {Convert/spell}, with no complexity added inside {Convert} could display huge numbers, simple fractions, or decimals, all as spelled-out words:

  • {{convert/spell |67|km|mi}}               ⊟ ষাট-সাত কিলোমিটার (৪২ মা)
  • {{convert/spell |67|km|mi|words=out}} ⊟ ষাট-সাত কিলোমিটার (চল্লিশ-দুই মাইল)
  • {{convert/spell |3/8|lb|kg}}     ⊟ তিন-eighths পাউন্ড (০.১৭ কেজি)

Eventually, after {Convert/spell} was refined, {Convert} was rewritten in Lua script with new options "spell=in" or "spell=on":

  • {{convert|spell=in |1,000.3|m|ft}} ⊟ এক হাজার দশমিক তিন মিটার (৩,২৮২ ফু)
  • {{convert|spell=on |7,500,000,000,004|mi|ly}} ⊟ সাত ট্রিলিয়ন পাঁচ শত বিলিয়ন and চার মাইল (এক দশমিক দুই সাত পাঁচ আট শূন্য আট চার ছয় দুই ছয় সাত পাঁচ এক light-year)
  • {{convert|spell=on |9|ft|m|frac=10}}      ⊟ নয় ফুট (দুই and সাত-tenths মিটার)

The formatting of numbers into words is so complex, with so many details, that it took months to spot problems in some particular phrases of larger numbers. If the original {Convert} template had been modified to try displaying the words, or handle 4-amount ranges, then it might have taken years to rewrite {Convert}, and expand all the related thousands of subtemplates, to provide the same level of accuracy as the wrapper templates.