Help talk:Template
From Meta, a Wikimedia project coordination wiki
If you have a question, please summarise your problem in the title; that way you will get an answer more quickly.
Archives |
|---|
[edit] Help:Template#Self-transclusion
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)
[edit] arguments count?
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)
- In the spirit of Patrick's solution, I have created {{Argcount}}. —Anonymous DissidentTalk 10:50, 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)
- 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)
-
-
[edit] archiving as subpages
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)
[edit] Can I supply multiple named parameters through a nested template?
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.
[edit] Question about the show/hide on templates
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. Happy‑melon 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:
- 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)
.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. Happy‑melon 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. Happy‑melon 16:01, 22 April 2009 (UTC)
-
-
-
[edit] The illusion of transclusion....
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. Happy‑melon 22:41, 11 June 2009 (UTC)
[edit] Self-transclusion Problem
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)
- 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.
- 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)
[edit] Why does this manual exist here and not at MediaWiki.org?
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)