Help talk:Template

From Wikipedia, the free encyclopedia
Jump to: navigation, search
the Wikipedia Help Project (Rated C-class, High-importance)
WikiProject icon This page is within the scope of the Wikipedia Help Project, a collaborative effort to improve Wikipedia's help documentation for readers and contributors. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks. To browse help related resources see the help menu or help directory. Or ask for help on your talk page and a volunteer will visit you there.
C-Class article C  This page does not require a rating on the project's quality scale.
 High  This page has been rated as High-importance on the project's importance scale.
 

Problem with if scripts[edit]

I'm a user on the Danish version of Uncyclopedia ([1]). I've been trying to get this template to work in a few days, but somehow it just won't do as I want. It's meant to create a table with two rows and a picture to the right. In the upper row, there is going to be security marks for a product, while the lower row is going to have up to four columns with product descriptions.

The problem lies in the upper row, as the lower row already works. Se the result here: [2]

Here's the script (most of it is in English; only security mark descriptions are in Danish). You should look at the script of this page, as Wiki puts everything into one line here:

{| border="1" class="metadata" style="width:100%; background-color:rgb(255,102,0)" | {{ #ifeq: {{{picton|0}}} | 0 | colspan="2" | }} style="align:center;" | {{ #if: {{{1mark|}}} | {| | [[billede:{{ #switch: {{{1mark|}}} | ætsende | miljøfarlig | lokalirriterende | giftig | eksplosiv | brandnærende | brandfarlig = {{{1mark|}}}.gif | #default = {{{1mark|}}} }}]] |- ! <big>{{{1head|}}}</big> |- | {{{1text|}}} |} | }} {{ #if: {{{2mark}}} | {| | [[billede:{{ #switch: {{{2mark|}}} | ætsende | miljøfarlig | lokalirriterende | giftig | eksplosiv | brandnærende | brandfarlig = {{{2mark|}}}.gif | #default = {{{2mark|}}} }}]] |- ! <big>{{{2head|}}}</big> |- | {{{2text|}}} |} | }} {{ #if: {{{3mark}}} | {| | [[billede:{{ #switch: {{{3mark|}}} | ætsende | miljøfarlig | lokalirriterende | giftig | eksplosiv | brandnærende | brandfarlig = {{{3mark|}}}.gif | #default = {{{3mark|}}} }}]] |- ! <big>{{{3head|}}}</big> |- | {{{3text|}}} |} | }} {{ #if: {{{4mark}}} | {| | [[billede:{{ #switch: {{{4mark|}}} | ætsende | miljøfarlig | lokalirriterende | giftig | eksplosiv | brandnærende | brandfarlig = {{{4mark|}}}.gif | #default = {{{4mark|}}} }}]] |- ! <big>{{{4head|}}}</big> |- | {{{4text|}}} |} | }} {{ #if: {{{5mark}}} | {| | [[billede:{{ #switch: {{{5mark|}}} | ætsende | miljøfarlig | lokalirriterende | giftig | eksplosiv | brandnærende | brandfarlig = {{{5mark|}}}.gif | #default = {{{5mark|}}} }}]] |- ! <big>{{{5head|}}}</big> |- | {{{5text|}}} |} | }} {{ #if: {{{6mark}}} | {| | [[billede:{{ #switch: {{{6mark|}}} | ætsende | miljøfarlig | lokalirriterende | giftig | eksplosiv | brandnærende | brandfarlig = {{{6mark|}}}.gif | #default = {{{6mark|}}} }}]] |- ! <big>{{{6head|}}}</big> |- | {{{6text|}}} |} | }} {{ #if: {{{7mark}}} | {| | [[billede:{{ #switch: {{{7mark|}}} | ætsende | miljøfarlig | lokalirriterende | giftig | eksplosiv | brandnærende | brandfarlig = {{{7mark|}}}.gif | #default = {{{7mark|}}} }}]] |- ! <big>{{{7head|}}}</big> |- | {{{7text|}}} |} | }} {{ #if: {{{8mark}}} | {| | [[billede:{{ #switch: {{{8mark|}}} | ætsende | miljøfarlig | lokalirriterende | giftig | eksplosiv | brandnærende | brandfarlig = {{{8mark|}}}.gif | #default = {{{8mark|}}} }}]] |- ! <big>{{{8head|}}}</big> |- | {{{8text|}}} |}|}} | {{ #ifeq: {{{picton|0}}} | 1 | rowspan="2" width="{{{pictwidth|}}}" }} | {{ #ifeq: {{{picton|0}}} | 1 | [[billede:{{{pictaddr|}}}|{{{pictwidth|}}}]] }} |- | {{ #ifeq: {{{picton|0}}} | 0 | colspan="2" }} | {{ #ifexpr: {{{cols|1}}} >= 1 |<div style="width: {{ #expr: 100 /{{{cols|1}}} }}%; float: left;">{{{1col|}}}</div>}} {{ #ifexpr: {{{cols|1}}} >= 2 |<div style="width: {{ #expr: 100 /{{{cols|1}}} }}%; float: left;">{{{2col|}}}</div>}} {{ #ifexpr: {{{cols|1}}} >= 3 |<div style="width: {{ #expr: 100 /{{{cols|1}}} }}%; float: left;">{{{3col|}}}</div>}} {{ #ifexpr: {{{cols|1}}} >= 4 |<div style="width: {{ #expr: 100 /{{{cols|1}}} }}%; float: left;">{{{4col|}}}</div>}} |} — Preceding unsigned comment added by 90.185.27.224 (talk) 18:00, 16 November 2008

Template naming conventions[edit]

I've suggested standardizing template naming, at Wikipedia talk:Template namespace#Template naming conventions. If you're frustrated with typing template names and constantly guessing at the right capitalization and spacing, please chime in. Michael Z. 2009-01-10 17:46 z

Onlyinclude help[edit]

On List of high schools in Orange County, California there is an onlyinclude command. I've tried moving it around and such but as it is transcluded on List of high schools in California the onlyinclude is visible on the mainspace. This is beyond me, I don't know how to hide the wiki command. Trackinfo (talk) 22:41, 22 February 2014 (UTC)

The <onlyinclude> - which is just above the heading "Public schools" - is present because the page is transcluded to List of high schools in California. It prevents the lead section (one hatnote and one paragraph) from being transcluded as well. However, there is a potential problem in that there is no matching </onlyinclude> and so transclusion finishes at the end of the page - with the result that the {{DEFAULTSORT:}} and categories end up on List of high schools in California as well, which is probably not a good idea. --Redrose64 (talk) 00:05, 23 February 2014 (UTC)
I made this edit which has fixed the problem. You might want to adjust some of the header levels at List of high schools in Orange County, California down by one: the level 2 headers at List of high schools in California are one per county, not one per school type within a county. --Redrose64 (talk) 00:12, 23 February 2014 (UTC)

how can I test for unsupported parameters?[edit]

Transclusions of complex templates like {{infobox language}} tend to accumulate unsupported parameters, added by people unfamiliar with the template. Some of these should be corrected, and some just deleted. Is there a way to test for such things? I coded that template to generate an error if certain specific parameter names are used, but that only catches ones I've noticed in the past. Is there a way to do this for any unsupported param? — kwami (talk) 22:14, 10 March 2014 (UTC)

Unused parameters just get dumped by the system, there is no way to catch them unless you know beforehand what parameters are being added that shouldn't be... This can be complicated by different casing and the choice of whether to use spaces or underscores. The only thing that I can think of that "could" be done would be to run a bot (or use AWB) to go through all transclusions of the template and replace the template calls with new calls searching for a regular expression without case sensitivity to replace all of the known parameters and variations with the proper parameter names and dumping the rest out. This could be a very tedious process, especially on highly transcluded templates, and I don't see it as being a net gain in most cases myself (unless you are running through all of the transclusions to fix a superseded parameter anyways). Just my thoughts... — {{U|Technical 13}} (tec) 22:23, 10 March 2014 (UTC)
pretty easy to do with WP:LUA, all you need is a list of the valid parameters, and it can tell you if one is being used that is not on the list. Frietjes (talk) 22:26, 10 March 2014 (UTC)
Regular Wikicode can't test for unrecognised parameters; all we can do is test for commonly-made errors. For example, if a page is about a steam locomotive, it probably has {{Infobox locomotive}}; and if we wish to show the weight of the loco (or its tender) in the infobox, several parameters are available: we might use |weightondrivers=80 tons |locoweight=80 tons |tenderweight=80 tons or |locotenderweight=80 tons depending on what the 80 tons specifically applies to. If we use the somewhat vague |weight=80 tons this would put the page into Category:Unusual parameters of Infobox locomotive template; but if we use e.g. |totalweight=80 tons this would do nothing. To do something if |totalweight=80 tons, the template would need to explicitly test for that - and would still not pick up |weightofloco=80 tons - or any other variant.
As Frietjes notes, writing a template in Lua can detect unrecognised parameters, and many of the citation templates like {{cite book}} will do just that: {{cite book|title=A Book|totallybogus=Hello World}}A Book.  Unknown parameter |totallybogus= ignored (help) --Redrose64 (talk) 22:59, 10 March 2014 (UTC)
Thanks. So I'd need to learn Lua, or have s.o. rewrite the template. Probably not worthwhile. We had a bot run a couple years ago, but usually this kind of thing is considered too trivial to get bot approval for. Thanks anyway. — kwami (talk) 00:10, 11 March 2014 (UTC)
a bot run is probably your lowest cost option, I would suggest asking Plastikspork. His/her bot was used to scan transclusions of Infobox power station (see this thread). by the way, you don't need to rewrite the infobox just to add some tracking (as I am sure you have noticed). I can create a general purpose module for detecting bogus parameters if there is interest. it would be under 25 lines in LUA. I might do it tomorrow if I have some time. Frietjes (talk) 00:30, 11 March 2014 (UTC)
Would it be possible to have it generate a category or something, so there's a centralized report? — kwami (talk) 00:51, 11 March 2014 (UTC)
{{infobox language}} invokes {{infobox}} which invokes Module:Infobox, so the core is Lua. I suggest asking this question at Template talk:Infobox. --  Gadget850 talk 01:09, 11 March 2014 (UTC)
Okay, thanks. I asked there and pinged Frietjes. — kwami (talk) 19:10, 11 March 2014 (UTC)
for anyone who is interested, this is now implemented as Module:Check for unknown parameters, and appears to be working. It's 26 lines of LUA (without comments or blank lines), instead of the predicted under 25 :) Frietjes (talk) 19:02, 24 March 2014 (UTC)

'looking forward'[edit]

Could someone give me a simple example of how a parameter can 'look forward' to another? I'd like to automate {{IPAc-ja}} so that if you enter 'n' as a value, the output will depend on the following parameter (n before t or d, m before p or b, ŋ before k or g, etc). Currently this has to be done manually, and the fact that Wiktionary nearly always gets it wrong suggests that is not a good idea. — kwami (talk) 22:20, 11 March 2014 (UTC)

{{IPAc-ja}} passes the characters one at a time to {{c-ja}} so you would have to also pass the next character each time. For example, {{#if:{{{3|}}}|{{c-ja|{{{3}}}}}}} could be changed to {{#if:{{{3|}}}|{{c-ja|{{{3}}}|{{{4|}}}}}}}. {{c-ja}} would then need code to test {{{2}}} for some values of {{{1}}}. This assumes that only the following and not the preceding character matters, i.e. if you have n|t then the code for n can depend on t, but the code for t cannot depend on n. PrimeHunter (talk) 23:56, 11 March 2014 (UTC)
Thanks. Any idea what I'm doing wrong here[3][4]? — kwami (talk) 01:35, 12 March 2014 (UTC)
What is #sub supposed to do? I haven't seen that before and it doesn't appear to be defined. Is there a reason to not just say ja{{{1}}}{{{2|}}}? PrimeHunter (talk) 01:57, 12 March 2014 (UTC)
#sub is described here. It would take much longer to give all possible combinations of two parameters. The #sub command is supposed to strip the second down to just the first letter, which is the only relevant bit. — kwami (talk) 02:02, 12 March 2014 (UTC)
That extension is not listed at Special:Version so it's not installed here (that was controversial for years until we got Lua). You can use {{Str left}}. PrimeHunter (talk) 02:11, 12 March 2014 (UTC)
That works perfectly! Thanks! — kwami (talk) 02:50, 12 March 2014 (UTC)
Good. If {{{2}}} is undefined then it simply produces those 7 characters, so {{Str left|{{{2}}}|1}} produces {. {{Str left|{{{2|}}}|1}} would produce empty. Maybe this doesn't matter in your templates. PrimeHunter (talk) 03:12, 12 March 2014 (UTC)
Better fix it to be sure. Thanks. (It doesn't seem to have been a problem, but I don't know why. It should've been.) — kwami (talk) 03:15, 12 March 2014 (UTC)

Asking for review[edit]

I have created a template in a sandbox that combines the Template:Archive box and the Template:Search archives in one template. Could someone please review the template? Perhaps someone can help me with the layout. Thanks! Template:Archive with search/sandbox Note: Links to archives and the search function are only shown if there is an actual archived section. --Fluffystar (talk) 16:35, 24 April 2014 (UTC)

Help with a template?[edit]

I was trying to make a footer template to go at the bottom of several films that Adam Gierasch directed. So far I have the films that he's directed but he also co-wrote a number of films with his wife Jace Anderson. I may re-do the template to encompass both of these, but I may do a separate one because I don't want to make the template too bulky- nor do I want to minimize Jace Anderson's contributions to the scripts. Gierasch himself says that he'll donate ideas and basic outlines, but she does all of the actual writing. Because of that, I don't want to have just "Adam Gierasch" at the top and then as such minimize her as a result. But then, listing both of them and then putting "films directed by ____" in the side might be bulky. In any case, the real reason I'm asking for help is that at the left hand side where it should have VTE it just says "error:page does not exist". I thought maybe it was a userspace thing, but it did it in the mainspace as well. I've created templates like this before, so I'm not sure what I'm doing wrong. I figured I should ask for help rather than leave a malformed box in the mainspace. You can find the template at User:Tokyogirl79/Adam Gierasch. Tokyogirl79 (。◕‿◕。) 13:51, 1 May 2014 (UTC)

The name parameter of a navbox is used to make the V T E links and must be the page name, in this case name = User:Tokyogirl79/Adam Gierasch. Change the parameter if the template is moved. PrimeHunter (talk) 14:23, 1 May 2014 (UTC)
(edit conflict) @Tokyogirl79: User:Tokyogirl79/Adam Gierasch is a navbox, and to get the v-t-e links to work, you need to set the |name= parameter to be exactly the same as the page name. So in this case you would use |name=User:Tokyogirl79/Adam Gierasch and if the page were later moved to Template:Adam Gierasch you would alter it to |name=Template:Adam Gierasch - or even |name=Adam Gierasch because the Template: part is unnecessary. --Redrose64 (talk) 14:27, 1 May 2014 (UTC)

Sanitize template input[edit]

Is there a method for sanitizing template input? For example, I'd like to remove apostrophes so as to have ''Saints Row 2'' (mobile) sanitize to Saints Row 2 (mobile). Thanks czar  20:12, 18 May 2014 (UTC)

You could put the parameter value through {{replace}}. Single apostrophes are often legit, as in O'Hara, so those need to be left alone; thus, you would need to use {{replace}} twice:
{{replace|{{replace|{{{parameter}}}|'''|}}|''|}}
The first (inner) pass would replace all instances of three consecutive apostrophes with the null string, the second (outer) pass would replace all instances of two consecutive apostrophes with the null string. --Redrose64 (talk) 20:27, 18 May 2014 (UTC)

Template that can detect being inside of an archived discussion[edit]

Is there a method for a template to detect whether it's inside a discussion that has been archived? Say a template within a discussion that would change when between {{Archive top}} and its bottom? Couldn't find anything in search czar  04:56, 24 May 2014 (UTC)

Technically, yes: but not solely with a template, we'd need to add something to the site CSS as well. What I'm thinking is that we define a new class - say changeifarchived - which behaves differently according to whether it's enclosed by {{archive top}} or not; it would make use of any class that is used by {{archive top}}. At present, {{archive top}} wraps the thread in <div class="boilerplate"> so we could make use of that; the downside is that the boilerplate class is used in other places for non-archival purposes. It might be best to also add a second class to {{archive top}}, say class="boilerplate archivedthread", and then we can set up the CSS rules
.changeifarchived {
  border: 1px solid blue;
}
div.archivedthread .changeifarchived {
  border: 3px dotted red;
}
Then we make sure that our template wraps its content in the new changeifarchived class - it doesn't matter if it uses <div>...</div> <span>...</span> or another element. Let's assume that we have a template called {{different if archived}} coded as
<span class="changeifarchived">{{{1}}}</span>
and we use it like this
{{archive top}}
Some archived text {{different if archived|with a template}} inside it.
{{archive bottom}}
:Some non-archived text {{different if archived|with a template}} inside it.
The effect would be like this:
The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.

Some archived text with a template inside it.


The discussion above is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Some non-archived text with a template inside it.
This isn't a working demonstration - I didn't set up any classes or templates. The border patterns are just examples. --Redrose64 (talk) 10:32, 24 May 2014 (UTC)
@Redrose64, would this require that the CSS rules be set in advance? It would be preferable to be able to style the change within the template (because a dotted border may not be the intended change across templates). It there any way to do this now with a template detecting that it's within a "boilerplate" class without going back to the sitewide CSS rules? czar  14:10, 24 May 2014 (UTC)
Unless I'm completely misunderstanding the request, this can most certainly be done with just templateFu. I'll take a better look in about 10 hours from my computer when I get home. — {{U|Technical 13}} (tec) 14:33, 24 May 2014 (UTC)
@Czar: There are two ways of applying styling. One is by placing inline styling into the style="" attribute of an HTML element, as in
<span style="border: 3px dotted red;">some styled text</span>
- these cannot be applied conditionally, and so there is no way for the border to be automatically coloured differently according to what surrounds that <span>...</span> element. The other way is by using style sheets - the CSS files - which are applied to the element by various means known as selectors. Selectors can get complicated, but they can pinpoint particular elements on a page according to criteria like "if an element of type x is inside another element of type y, style it this way, otherwise style it that way". Class selectors are perhaps the easiest to understand - in my first boxed example above, the first line begins .changeifarchived - this means "any element that has the changeifarchived class should be styled this way". The fourth line begins div.archivedthread .changeifarchived - this means "any element that has the changeifarchived class, and which is also enclosed by a <div>...</div> element that has the archivedthread class, should be styled this way"; it uses the descendant combinator to specify this.
When you write templates that style the text, they can use either the style method or the class method; but to utilise the class method, the classes concerned need to be defined in a CSS file. Since we can't set these up on a per-page or per-template basis, they would need to go into the site CSS. See for example the request at MediaWiki talk:Common.css#Glossary classes. --Redrose64 (talk) 14:38, 24 May 2014 (UTC)
Thanks for the write-up. I'm already familiar with how CSS works. I wanted to use this not to style a section differently when inside a boilerplate/changedifarchived class (though that can be useful for other reasons), but to automatically remove a category (as added through a template) when the section has been archived. czar  15:02, 24 May 2014 (UTC)
I'm pretty sure that it's not possible, since open WP:AFD debates have a {{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD}}, the sole purpose of which is to add two categories (like Category:AfD debates (Not yet sorted) and Category:AfD debates) which needs to be manually removed when the AFD is closed. --Redrose64 (talk) 15:10, 24 May 2014 (UTC)
Okay. Part of me asking was to see whether that could be helped (and, you know, it would be useful for other reasons) czar  15:13, 24 May 2014 (UTC)
  • From what I can read on my phone, what you want is possible inside of a template although it is not instantaneous as it requires waiting for the job queue to keep it updated and sometimes requires a null edit of which there are bots for. — {{U|Technical 13}} (tec) 15:30, 24 May 2014 (UTC)
@Technical 13, I'd be interested in reading more about this if you can send me a link when you get to a computer. Thanks for your help, all czar  15:39, 24 May 2014 (UTC)
  • Ahh.. okay, now I can read it better. When you say archived, you just mean closed to future discussion, and not actually archived on the archive page. I do believe that can be done with Lua, it can also be done with css as Rose suggests in cooperation of a template, or it could be done via JavaScript. "If" you had meant what I thought you did of it actually being archived on an archive page, then the template could read the pagename, check to see if "archive" was included in the title, and style or change the categories with parser functions. — {{U|Technical 13}} (tec) 21:47, 24 May 2014 (UTC)

Lang-eu[edit]

There seems to be a display problem specific to the Basque-language version of {{Lang}}. At Asno de las Encartaciones I wanted the opening of the lead sentence to read "The Asno de las Encartaciones, Basque: Enkarterriko asto, is ..." (which of course I could do by writing it in that way, without using the template at all). But using {{lang-eu}} produces this result: "The Asno de las Encartaciones', Basque: Enkarterriko asto', is ...". Changing the language to, say, Spanish, (i.e., changing the letter u of eu to an s without making any other change) causes it to display as expected. Can anyone see what the problem might be (most likely is user error, of course); or even fix it? Thanks, Justlettersandnumbers (talk) 11:23, 9 July 2014 (UTC)

@Justlettersandnumbers: My second attempt seems to have worked, but I have no idea why {{lang-eu}} and {{lang-es}} behave differently. -- John of Reading (talk) 12:19, 9 July 2014 (UTC)
Yes, your fix is good (I thought I'd tried that, but obviously not); but it doesn't solve the underlying problem, which as far as I know is limited to this one variety of {{Lang}} (of course, I haven't actually gone through the other 200? 300? to check), and I think needs looking at. Justlettersandnumbers (talk) 13:33, 9 July 2014 (UTC)
This edit is the proper fix. --Redrose64 (talk) 15:23, 9 July 2014 (UTC)
Ha! Obvious once it's been pointed out. -- John of Reading (talk) 16:29, 9 July 2014 (UTC)