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.
WikiProject Templates
WikiProject icon This page is within the scope of WikiProject Templates, a group dedicated to improving the maintenance of Wikipedia's templates. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.

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 (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

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:
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)


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)

How to variablize Category url[edit]

I'm having trouble creating a link to a Category page utilizing a variable string passed as a parameter: [[Category:{{{unit_class}}}]] How does one do this properly? (talk) 15:01, 16 September 2014 (UTC)

If you mean placing the page in a category then [[Category:{{{unit_class}}}]] is correct syntax (it requires {{{unit_class}}} to have a value), and the problem must lie elsewhere if it doesn't work for you. If you mean creating an inline link at the place of the code then you must place a colon in front of the category name like [[:Category:{{{unit_class}}}]]. This is a general category feature unrelated to templates. For example, [[:Category:Wikipedia help]] produces Category:Wikipedia help without placing this talk page in the category. PrimeHunter (talk) 15:21, 16 September 2014 (UTC)
Thanks for your reply. An example is at notice in the infobox, on the right, with the field labeled "Type"? You see it blank, which I dont'get, see the Template:Unit at Enorl76 (talk) 18:47, 16 September 2014 (UTC)
As mentioned, if you want to display an inline link to the category in the infobox then you must place a colon in front like [[:Category:...]]. If you both want to display the category link in the infobox and place the page in the category then you must do both: [[:Category:...]][[Category:...]]. Currently the template only says [[Category:...]]. That isn't supposed to display anything where the code is placed. It only places the article in the category and places a link to the category at the bottom of the article. All of this is basic category features and unrelated to templates and parameters. See Help:Category. PrimeHunter (talk) 22:58, 16 September 2014 (UTC)

Template:Infobox election[edit]

Earlier today this template began appearing malformed on articles (e.g. Next United Kingdom general election, German federal election, 2013). The template itself has not been edited since December last year, so I assume an underlying template has been broken. Can anyone help out? Please comment at Template talk:Infobox election. Cheers, Number 57 10:58, 6 October 2014 (UTC)

This has been resolved. -- John of Reading (talk) 11:33, 6 October 2014 (UTC)

Good faith confusion about includeonly[edit]

@Redrose64: Umm you've got a point. Apologies. I will correct this on the transclusion page. --Mrjulesd (talk) 01:37, 15 November 2014 (UTC)

Templates showing[edit]

All templates seem to be collapsed right now? WikiOriginal-9 (talk) 21:15, 12 December 2014 (UTC)

I'm not seeing this. Looking through your recent contributions for clues, I found and fixed an error in the Going postal article - was that the problem you were referring to? -- John of Reading (talk) 22:12, 12 December 2014 (UTC)
All the navboxes I come across are all expanded (fully visible) - (I didn't mean to say collapsed earlier) and the show button is missing. WikiOriginal-9 (talk) 22:22, 12 December 2014 (UTC)
I'm not seeing that either. Do you have JavaScript turned off in your browser? [I'm about to go offline, BTW]. -- John of Reading (talk) 22:37, 12 December 2014 (UTC)
Thanks, it's fine now. I had it on though, so idk. WikiOriginal-9 (talk) 22:47, 12 December 2014 (UTC)

Help creating a template for Encylcopedia Virginia listings[edit]

I have a quick question: would it be possible to create a template for Encyclopedia Virginia articles akin to how we have templates for listings at IMDb or Find-A-Grave? (IE, like this: {{IMDb title| xxxxx }}) The reason I'm asking is that there are a lot of articles at EV that have articles on here and it'd be a valid external link for these articles since the EV would be able to have links to various multimedia and whatnot that might not be available on Wikipedia. Plus they can go into more minutae than we can on here and it's a reliable source (vetted and all) so it'd be a useful external link. (If you're curious, here's a link to the entry for St. George Tucker to show what I mean by multimedia and such.) I can do without it, but I've never created anything of this nature before and it'd just be something nice to have. (Full disclosure, I'm Tokyogirl79 editing under a different name for my volunteer position at the Library of Virginia.) Tokyogirl79LVA (talk) 16:37, 4 March 2015 (UTC)