Help talk:Template

From Meta, a Wikimedia project coordination wiki
Jump to: navigation, search

If you have a question, please summarise your problem in the title; that way you will get an answer more quickly.

Archive
Archives

2007 | 2008 | 2009

Help:Template#Self-transclusion[edit]

Does anybody know where in the parser code can we make a change so that self-transclusions are allowed? Hillgentleman 02:38, 12 March 2009 (UTC)

arguments count?[edit]

is there a way to count how many arguments ({{template|a|b|c|d|...}} => {{{1}}},{{{2}}},...) are used in the call of a template? 89.2.186.67 17:28, 12 March 2009 (UTC)

If empty counts as undefined the number of unnamed arguments (up to a maximum) can be found using an expression like {{#expr:{{#if:{{{1|}}}|1|0)}}+{{#if:{{{2|}}}|1|0)}}+{{#if:{{{3|}}}|1|0)}}}}.--Patrick (talk) 07:19, 14 March 2009 (UTC)
In the spirit of Patrick's solution, I have created {{Argcount}}. —Anonymous DissidentTalk 10:50, 15 March 2009 (UTC)
Of course, for now, the template won't really function because it can only be applied to itself. I wonder if there is a way to implement this another way. —Anonymous DissidentTalk 10:55, 15 March 2009 (UTC)
The only way to pass on arguments to the next template is by something like the call {{argcount|1={{{1|}}}|2={{{2|}}}|3={{{3|}}}...}}. However, you may customise your template argcount so that it can be substituted. Hillgentleman 02:25, 16 March 2009 (UTC)
Your idea is a good one; I'll test it presently. However, substitution seems to make the template pointless; it was made to theoretically save space. —Anonymous DissidentTalk 11:54, 16 March 2009 (UTC)
I was hoping to use this to iterate through N number of arguments, is there really no way to do this?64.111.160.29 21:07, 11 December 2012 (UTC)
Figured it out, but without using argCount...
{{#vardefine: i | 1}}
{{#while:
|{{#ifexpr: {{{ {{#var: i}} |}}} | 1 | 0 }}
|<nowiki/>
{{{ {{#var: i}} }}}
{{#vardefine: i | {{#expr: {{#var: i }} + 1 }} }}
}}

archiving as subpages[edit]

Since this page gets tonnes of questions, why don't we archive them as subpages and then we would have a set of faqs via the prefixindex? Hillgentleman 08:32, 14 March 2009 (UTC)

Can I supply multiple named parameters through a nested template?[edit]

I would like to defined the parameters to a template in another template. For example, have a template called "params", which only contains: param1=a | param2=b | param3=c, and then include those parameters in the call to another template: {{showparams|{{params}}}}, where "showparams" could be: 1st parameter: {{{param1}}}, 2nd parameter: {{{param2}}}, 3rd parameter: {{{param3}}}..

This would create database-like functionality, where I can format the same data in different ways, without supplying the data on every call to the formatting template.

However, the result seems to be that my parameter-list is instead interpreted as a single, unnamed parameter (which can be retrieved with {{{1}}}).

Is it in any way possible what I am trying to do? The preceding unsigned comment was added by Pbb (talk • contribs) 13:38, 16 March 2009.

Question about the show/hide on templates[edit]

I wanted to know how to implement the show/hide tab that you see on the right side of template on title bars. I had translated this from the English wiki into this onto Punjabi wiki. But the show/hide tab doesn't show up (the one you see on right side to collapse the template). I would really like to know how that would be implemented. Thank You. --Gman124 03:24, 22 April 2009 (UTC)

You need the CollapsibleTables code from en:MediaWiki:Common.js, to copy into the equivalent file on pawiki. Happymelon 09:22, 22 April 2009 (UTC)
The show/hide box doesn't show up yet. Did I copy the right stuff. also would it be okay that I copied the entire script? --Gman124 13:45, 22 April 2009 (UTC)
Vis the first version of your post, you also need some code from our en:MediaWiki:Common.css:
.collapseButton {          /* 'show'/'hide' buttons created dynamically */
    float: right;          /* by the CollapsibleTables javascript in    */
    font-weight: normal;   /* [[MediaWiki:Common.js]]are styled here    */
    text-align: right;     /* so they can be customised.                */
    width: auto;
}
For the second version, remember that the site JS is cached for 30 days in people's browsers, so the new script won't be available to everyone for up to a month (depending on how much longer their browser's cached copy lasts). You can get a new copy of the script immediately by purging your browser's cache (shift+F5 or Ctrl+F5 depending on browser). With regards copying, it's completely fine because the two sites have the same license (GFDL). The CollapsibleTables javascript has been copied all over the place. Happymelon 14:43, 22 April 2009 (UTC)
It works now. Thank you very much for your help. Gman124 15:48, 22 April 2009 (UTC)
You're welcome. Regarding (again) the first version of your post, that code also sets the tab at the top to say "main page" instead of "article". You don't need that section, or many of the others; the only sections you definitely need for CollapsibleTables to work are the ones marked "test if an element has a certain class" and "collapsible tables" itself. The others do wildly different things, not all of which will be relevant to your wiki. Happymelon 16:01, 22 April 2009 (UTC)

The illusion of transclusion....[edit]

I think I have found a problem, or just a limitation. I have a page that uses templates to build another template call. Instead of getting the resulting template transcluded I just get the wikitext displayed. I am guessing based on my result that mw makes a single pass over the page for parsing, is there anyway to invoke a second pass? Expand templates actually shows the page correctly.

an example can be found here, http://scratchpad.referata.com/wiki/Thismightwork. 67.97.209.36 21:01, 9 June 2009 (UTC)

No, this doesn't work, and shouldn't; it would open the possibility of infinite recursion in the preprocessor. As you say, MediaWiki only makes a single pass over the templates on a page: templates are expanded recursively, but there is no re-evaluation of the resulting wikitext. ExpandTemplates shouldn't handle this any differently; if it does, that is a bug. Happymelon 22:41, 11 June 2009 (UTC)

Self-transclusion problem[edit]

I'm writing a template for use on Template pages that displays a complete description of usage and functionality for a parameter in the template. The obvious first use for this would be in the <noinclude></noinclude> description section of the template itself to describe the templates own parameters. However, due to the self-transclusion rules, I just get the wikitext bolded name of the template's page. I tried subst, but that literally drops in the text of the template upon saving, which completely defeats the purpose. Is there no way to use a template on the template's own page when it is NOT in the template's code itself?
--20.4.235.68 19:35, 2 October 2009 (UTC)

I managed to solve this already through some random trial and error. However, I am rather baffled by the solution. Apparently, in order to include a template on the template's own page, but not in the template's own code, you MUST use the format {{Template:Template Name}} when beginning use of the template. I'm not sure why exactly this is, but it seems to work.
--20.4.235.68 19:54, 2 October 2009 (UTC)
Here on Meta (and other wikis I know) this is not needed, for example Template:Tc is called in its own noinclude part (indirectly, but directly it also works).--Patrick (talk) 08:48, 3 October 2009 (UTC)
Yeah, apparently it was coincidence that I tried that and it worked at the same time. It appears to be some sort of preprocessor caching thing. I have to edit the template, save it, preview it, then save it again to get self-transcluded things to update properly.
--98.236.95.231 21:26, 3 October 2009 (UTC)

Why does this manual exist here and not at MediaWiki.org?[edit]

According to the Meta:About Meta, the site isn't a place to describe the MediaWiki software. Why then hasn't this in-depth page (and indeed, the entire series of "MediaWiki Handbook" pages) been migrated over yet? --J.nesta 01:42, 7 November 2009 (UTC)

MediaWiki hosts public-domain help pages that can be freely copied to any wiki without licensing issues. Since the help pages on Meta are copyrighted and GFDL-licensed, they cannot be copied over. Feel free to improve to mw:Help:Template or the other PD help pages. —Pathoschild 02:54:16, 07 November 2009 (UTC)
Thanks to call our attention J.nesta, this page should be moved to where it belongs and only the usage of templates should be kept in WM (see also MetaProject_to_transfer_content_to_MediaWiki.org). I cannot agree Pathoschild because MW and WM has exactly the same copyright restrictions, Creative Commons Attribution/Share-Alike License (a.k.a. CC-BY-SA), as mentioned at the bottom of every page. And as the name implies, "you can share content under the same or similar license to this one". ("Public-domain" (a.k.a. CC-PD) is more than that, meaning "No Known Copyright".)
MW's PD help Project was started in 2005 long before the CC usage. Note that MediaWiki installs are pre-setting the sites copyright status to CC.
See also Interoperability between Creative Commons licenses and GFDL.
So, I cannot help placing the {{MoveToMediaWiki}} tag to this page. --Vikici 05:15, 18 December 2010 (UTC)
The help pages on Meta are based on the extensions and settings applicable on Wikimedia sites, while the MediaWiki site describes the basic installation, and separately each extension, and on the MediaWiki site settings are treated as variables that can be chosen by someone setting up a MediaWiki site. Thus pages can better be copied and adapted than moved, although currently there is not even a namespace on the MediaWiki site for help pages which are not public domain, see also mw:User hub.--Patrick (talk) 07:30, 18 December 2010 (UTC)
I agree that Meta needs a Help:Template page (with a set of necessary sub/side pages), and although wording belongs to the transfer project, instead of moving we should better use transfer or distribute help content among the software and its customization: Site builders and maintainers, writing most of the essential templates, belong to the software users community while the wikipedians or mediapedians are the content writers, users of the customized platform. The borders are not so sharp but the distinction is obvious. Likewise, help documentation of template technology and coding technique should be provided by the software while the documentation of the usage and (to some extent) the language basics should be made available for the latter group by the site maintainers (the public domain help development within MW makes this work ). And (last but not...), it should be considered that there are quite a lot MediaWiki sites apart from Wikimedia family.--Vikici
Feel free to copy the page, and adapt the copy depending on the destination site and depending on the type of user for whom the copy is intended. Since you agree that Meta needs a Help:Template page I removed the move tag.--Patrick (talk) 07:46, 19 December 2010 (UTC)
I am talking about the necessity of this page, not with this content. And I utsed the only tool available, the {{MoveToMediaWiki}} tag to show this -and yes, the wording of the tag should be changed. Anyway, I must insist that this page should be kept in minimum giving only the basic definition and the relevant links to he main articles, including the MW:Help:Template link where Wikimedia community should share this "core" information together with the other MW software users. But I will not involve in a so called rv war, and quitting. --Vikici 16:28, 19 December 2010 (UTC)

Internal variables in a template[edit]

Forgive me if this is a n00b question, but I just can't seem to find a clear answer anywhere. I've built a template that has two named parameters. In the template, I use the values passed in through the parameters to compute a third value. I'd like to assign it to a variable so I can use it again and again in the template. This variable would be internal to the template only. How do I do this? Thanks! –189.153.69.48 05:01, 24 January 2010 (UTC)

It is not possible, you need mw:Extension:VariablesExtension. However, to avoid repetition of a long expression (longer than a template call) in the wikitext, you can make a subtemplate for the computation.--Patrick (talk) 08:53, 24 January 2010 (UTC)

Templates as template parameters[edit]

I would like to create a template which takes another template (with the second template's full set of parameters) as a parameter, and which will display the second template as part of its output. It is relatively easy to make a template which takes another template without parameters as its parameter, simply with {{ {{{1}}} }}, but this is insufficient; obviously, the | character cannot be used for its ordinary purpose in this case, since the wrapper template would parse it as the start of a new parameter and never pass the rest to the subtemplate, but using either {{!}} (which is implemented on the wiki in question) or the HTML entity &#124; results in the text {{ template|argument }} appearing in the output instead of the intended result. Is there any way to do what I want? --AutoDisplace 22:05, 16 March 2011 (UTC)

If you mean "takes the name and parameters of another template as parameters": {{ {{{1}}}|{{{2}}} }} etc.--Patrick (talk) 00:47, 17 March 2011 (UTC)
There are multiple templates which could conceivably be used in this way, each with a different set of named and unnamed parameters, so I was hoping that there was a way to give the outer template a single argument which holds the entire list of arguments for the inner template. It seemed like a simpler and more extensible alternative to making a parameter in the outer template for each possible parameter in any of the inside templates. But, if it's not possible, that's no big deal, since I can just do that instead.--AutoDisplace 01:13, 17 March 2011 (UTC)
Of course you can also pass the result of a template call as parameter value to another template. Alternatively, if you want to construct composite data items, see Help:Array.--Patrick (talk) 10:53, 17 March 2011 (UTC)
Oh, the array thing should work. Thanks!--AutoDisplace 19:10, 17 March 2011 (UTC)

Old merge proposal[edit]

JFTR, Help:Template demo calling alternative for redirect contains a link to User:Happy-melon/Templates, and User:Happy-melon/Templates has a merge tag proposing to merge it with the subject page Help:Template.  If there is no better page on meta explaining <noinclude>, <includeonly>, and <onlyinclude> please make it so.  The proposed merge was apparently archived here, but the link on Help:Template demo calling alternative for redirect suggests that it was not resolved, let alone rejected.  –82.113.106.28 02:03, 26 April 2011 (UTC)

Passing hex color codes requires <nowiki> on client-side[edit]

At en:Template talk:Taxobox, we've discovered a large number of instances where a hex color code is entered (e.g. |color=#FF00FF). Unfortunately, MediaWiki parses the pound sign as an ordered list item before the parameter can be used in the template code itself, which completely breaks the template. The only workaround I've found so far is to do something like |color=<nowiki>#FF00FF</nowiki>. Is there any way to fix this so users don't have to use the <nowiki> tag? Bob the Wikipedian 18:02, 16 May 2011 (UTC)

See Help:Newlines and spaces#Automatic newline. In w:Template:Taxobox/core, move background-color: inside the if-clause, so that its result does not start with #.--Patrick (talk) 21:37, 17 May 2011 (UTC)
Thanks for that. I've implemented that, as well as the applications of {{;}} and {{COLON}}. It appears to be working very nicely now! Bob the Wikipedian 22:25, 17 May 2011 (UTC)

Suppressing math[edit]

How do I suppress math in a passed parameter? See the hyphenated range I passed through the birdbox at en:User:Bob the Wikipedian/Sandbox. Bob the Wikipedian 22:22, 11 June 2011 (UTC)

Math is only performed with #expr and #ifexpr. It seems you try to use an undefined {{{hyphenposition}}} in an expression..--Patrick (talk) 08:58, 12 June 2011 (UTC)
Well, the issue changed by the time you responded; sorry for the confusion. And actually, {{{hyphenposition}}} is defined from the call made at en:User:Bob the Wikipedian/Birdbox/population. Bob the Wikipedian 20:31, 13 June 2011 (UTC)

Summarising data from templated pages[edit]

If I have a set of pages based on the same template, is it possible to create a page that summarises them? For example, say I had a template with variables PetName, PetAnimal, PetOwner, PetBiography and PetFavouriteToy and I created a load of Pet pages from it. Is there any way to build a Pets List page with a list of all the pets' names and what animal they are, or would I have to maintain my Pets List page manually?

You cannot automatically retrieve on a page the value of a given parameter in a call of a given template on a given other page, but Help:Array explains some techniques for storage and retrieval of the elements of your "2D array".--Patrick (talk) 13:38, 12 July 2011 (UTC)

Generating links from a list passed as a parameter[edit]

I have a template in which one of the parameters is expected to be a list of vaiable length. I would like to make each member of this list into a link with a prefix. I would call the template like this: {{foo|fooName=My Favourite Foo|fooDesc=My favourite foo has long blue fur. It likes pasta but not noodles.|barList=bar83,bar24,bar45}}

And the output I want is


My Favourite Foo[edit]

My favourite foo has long blue fur. It likes pasta but not noodles.

Related bars[edit]

The template would be something like

Template:foo =={{{fooName}}}== {{{fooDesc}}} ==Related bars== ??? what goes here ???

What do I need in the ??? what goes here ??? part?

Assuming you don't want to use {{{1}}}, {{{2}}}, etc, there's no simple way to do it. You'd need to implement functional templates to search for commas, parse, and recurse. Bob the Wikipedian 03:18, 11 July 2011 (UTC)
Slashes work better than commas, see Help:Titleparts.--Patrick (talk) 15:02, 12 July 2011 (UTC)

Help[edit]

Why does this give me a template recursion error?

Through the template it includes itself. It looks like you mean onlyinclude instead of includeonly in the template.--Patrick (talk) 05:48, 21 September 2011 (UTC)

Would be nice to be able to view Templates, or to Download them[edit]

If I could just view a Template here, that would be great. But I gather that templates are hidden for some reason. Oh well.

Trying to export templates according to Help, Copying from one wiki to another, does not work as described -- or I am just not understanding it properly.

For example, a Page here refers to Template:TOCright, but I have been unable to export it. There are many, many templates! and I have been able to export only a few; export just refuses to export more than that.

It would be nice to have a actual way to download templates if they can not be viewed. Can't I get a template as a text file? Is there an archive of templates somewhere?

Otherwise, all cool here...

151.204.232.16 06:42, 3 January 2012 (UTC)

Sometimes the template page does not show any result because it does not make sense without parameters filled in. However, you can go to the page, e.g. Template:TOCright and press edit to view and copy the wikitext. For the special export operation see Help:Export.--Patrick (talk) 08:26, 3 January 2012 (UTC)

Transcluding a <noinclude> tag[edit]

I have a subtemplate that I want to include <noinclude> tags. I have this:

<noinclude>{|
! Type !! Name !! Description</noinclude>

I want it, when transcluded into the main template, to remain with the the <noinclude> tags in place. So that main template would result in this:


<noinclude>{|
! Type !! Name !! Description</noinclude>
|-
| etc
<noinclude>|}</noinclude>

Is there any way to achieve such behaviour? The preceding unsigned comment was added by 87.112.178.122 (talk • contribs) 17:46, 23 April 2010 (UTC)

Like that ? <noinclude>string1</noinclude> JackPotte 19:39, 23 April 2010 (UTC)
Not quite. I'd like the main template not to show the text within the transcluded <noinclude> tags when it itself is transcluded. If you interpret the <noinclude> tag as "Remove on first-level transclusion", I'd like a method to achieve "Remove on second-level transclusion". Hope that clarifies things 87.112.178.122 19:59, 23 April 2010 (UTC)
I have the same problem. Is there a solution for it? -- Abrafix (talk) 19:14, 10 October 2012 (UTC)
So I think theres no solution for it... :( -- Abrafix (talk) 21:08, 16 October 2012 (UTC)

Template with chart and caption[edit]

I am trying to create a template with a chart with an optional caption. Like so here: en:Template:Subschools of Vedanta. Unfortunately, for longer captions, I have been unable to enforce text wrapping so that the template retains the width of the chart. Any help is greatly appreciated. Thanks. Chaipau (talk) 19:18, 12 May 2013 (UTC)

Number of parameters / Catching misnamed parameters[edit]

I am producing a template that expects a varying number of named parameters. I would like to be able to catch somebody using the template with a misnamed parameter, but can't find a mechanism to add an error check for that. I can add a check for any unnamed parameters being added, since a #if can be used on {{{1|}}}, but not for a named parameter the template wasn't expecting. Iantj (talk) 07:32, 16 May 2013 (UTC)

Nowiki (text) parameters[edit]

Hi. Is it possible to force parameteres to be plain text? I want to use parameters in links and be able to use brackets in them.

Effectively change this:

{{bug|123|[tag] whatever}}

To this:

[http://bugs.r.us/123 <nowiki>[tag] whatever</nowiki>]

--Nux (talk) 11:10, 24 July 2013 (UTC)

parameter without explicit value[edit]

For a template I'm creating, how do I set up a parameter so that its value is implicit? I'd like the parameter to behave like it does in another template, but that template is too complicated to copy and modify for what I need, so I'm coding from scratch. I can provide that the parameter "s" will respond to "s=yes", but I'd like it to respond to just "s", by implying the "yes". How can I do this? A template that does this now is the subscription required template. My template draft has its implementation effects visible at my sandbox (both in en-WP). I asked a similar question at MediaWiki's support desk but the question has already been buried on an inner page unanswered. This issue probably should be covered in the Help:Template page or somewhere else. Thanks. Nick Levinson (talk) 16:29, 19 August 2013 (UTC)

Solved: I discovered that the technique I was looking for was to use an anonymous parameter. Nick Levinson (talk) 17:01, 1 November 2013 (UTC)