Help talk:Substitution

Why substitute?
I don't understand this help page and I doubt that anyone else without a lot of experience in Wiki coding would either. Can someone explain the reasons for substitution, other than the expanded text, to me in plain English? Also, as a general comment, I have to say I find filling in the gaps in the expanded text difficult, laborious and not at all user-friendly. Thanks.Grant65 | Talk 07:48, 11 January 2007 (UTC)
 * One could add pedagogic --Nopetro 17:08, 16 June 2007 (UTC)
 * See "Benefits of substitution" on Template substitution. Dar-Ape 19:21, 28 November 2007 (UTC)

Template with substitution and subsequent transclusion
I am trying to build a template that includes the title of the page that is using the template. Simple enough, use:

However, I plan to transclude the template using page onto other pages and want a link back to the template using page automatically created. So I did the following

But, this substituted the title of the template page and not the template using page. Not what I wanted. The solution seemed easy enough, surround the the code with includeonly tags so that the substitution occurs on the template using page rather than on the template page its self:

The result of that, however, is to literally display " " on the template using page, not the desired result.

I've tried all sorts of other combinations, including only the "subst:", substituting the substitution, including only the substitution of the substitution, including only the included only substitution of the substitution, this thing --> (which wouldn't work anyways because the link back would be to a page that doesn't necessarily exist).

Advice? Suggestions? Ideas? 192.75.172.1 (talk) 19:11, 28 November 2009 (UTC)
 * I think I was trying for much the same effect. Try, for a working example (for now) see User:Unomi/hex. un☯mi 10:51, 19 August 2010 (UTC)

Clarify
Like much of help-space this is poorly written, and uses examples from Meta that don't exist here. Any wiki clarificaton would be a good thing. Rich Farmbrough, 19:49, 19 June 2010 (UTC).

utterly demotivating
I can only emphatically agree with the criticism directed at the current documentation.

I am trying to get a substitution template to evaluate prior to being substituted in, and I am not able to parse to the documentation enough to figure out how to get that done.

If someone is able to tell me how to achieve that I would be very much in their debt, in return I shall update this page :) Please see here, feel free to edit it for effect. The result of should be only the result of the evaluation, not having the logic embedded on the page, Many thanks in advance, un☯<b style="color:#f30">m</b><b style="color:#f00">i</b>  08:47, 19 August 2010 (UTC)


 * It seems you found it?--Patrick (talk) 11:54, 19 August 2010 (UTC)
 * I managed to find a signature subst template which implements it. But it seems like something so useful that it could do with being presented here, or at least more clearly if it already is :p <b style="color:#771">u</b><b style="color:#670">n</b><b style="color:#570">☯</b><b style="color:#470">m</b><b style="color:#370">i</b> 11:56, 19 August 2010 (UTC)
 * By the way, do we have any hexadecimal helpers? I see that Template:Digit uses a decimal rendition of base 16 . <b style="color:#948">u</b><b style="color:#847">n</b><b style="color:#747">☯</b><b style="color:#647">m</b><b style="color:#547">i</b> 11:58, 19 August 2010 (UTC)
 * Does do what you want? -- Red rose64 (talk) 12:35, 19 August 2010 (UTC)
 * Lovely! Thanks! :) <b style="color:#863">u</b><b style="color:#762">n</b><b style="color:#662">☯</b><b style="color:#562">m</b><b style="color:#462">i</b> 12:42, 19 August 2010 (UTC)

I now see there is also, when it rains it pours I guess :) <b style="color:#596">u</b><b style="color:#495">n</b><b style="color:#395">☯</b><b style="color:#295">m</b><b style="color:#195">i</b> 12:49, 19 August 2010 (UTC)

Substituting only the template output
Is it possible to substitute only the template output, instead of all the other mess (like the switches and if-tags, etc, like in the template)? / Hey Mid  (contributions) 12:14, 4 September 2010 (UTC)


 * See m:Help:Substitution.--Patrick (talk) 13:17, 4 September 2010 (UTC)
 * I don't get it. Could you try and subst without all the nonsense (e.g. only the context output) here? / Hey  Mid  (contributions) 13:52, 4 September 2010 (UTC)
 * Not sure what you want here. I have looked at User:Heymid/Test, and I see this:
 * To create a link to a template, without transcluding it, you don't need to do this; just prefix the template name with, ie  , which yields time. There's a whole family of these, such as . -- Red rose64 (talk) 17:54, 4 September 2010 (UTC)
 * No. I want to transclude the template, but I don't want to include all the mess like the switches and if-tags, only the text output. / Hey Mid  (contributions) 18:16, 4 September 2010 (UTC)
 * Like [ here] (done with . But as you can see, it added the whole mess too. I only want the "21:32, September 4, 2010 (UTC)" part (only the outputted text) to be transcluded, not the whole mess too. Also, it seems that does not work, returns the red error message "Invalid time". But if I do not subst it, it works fine. What is wrong with that? How can I subst a template with a ,  variable or to a named attribute?
 * Like [ here] (done with . But as you can see, it added the whole mess too. I only want the "21:32, September 4, 2010 (UTC)" part (only the outputted text) to be transcluded, not the whole mess too. Also, it seems that does not work, returns the red error message "Invalid time". But if I do not subst it, it works fine. What is wrong with that? How can I subst a template with a ,  variable or to a named attribute?


 * Take my above questions one by one. / Hey Mid  (contributions) 21:40, 4 September 2010 (UTC)


 * I adapted Template:Time, Template:Time/EET offset and Template:Current daylight saving offset in Europe, the other indirectly used templates have to be adapted in a similar way.--Patrick (talk) 21:50, 4 September 2010 (UTC)
 * I made some more changes to Template:Time, which I forgot.--Patrick (talk) 05:57, 5 September 2010 (UTC)

Detect subst
I would like to make a template, say ABCD which has to take CURRENTDAY as a mandatory parameter. So the use of is not permitted, but users should use. Now, if some user uses in an article, it should display the message Please use  instead of the template  . How can I detect inside the template ABCD whether subst has been used or not? --Sreejith K (talk) 10:13, 18 November 2010 (UTC)
 * Project banners are able to do it, try sandboxing . It's partly done with the template, also some code in . -- Red rose64 (talk) 13:55, 18 November 2010 (UTC)
 * Splendid. I could replicate this using two templates. Great. Still, I would love to know if this can be done in a single template itself. --Sreejith K (talk) 12:29, 19 November 2010 (UTC)
 * I don't know if it can be done easily in one template. The discussion at Template talk:! implies that there is no existing template which would do this. -- Red rose64 (talk) 13:40, 30 December 2010 (UTC)


 * You can use something like
 * Patrick (talk) 16:42, 30 December 2010 (UTC)
 * Patrick (talk) 16:42, 30 December 2010 (UTC)

safesubst section does not make sense
Could someone who understands  please rewrite that section of the page? It is utterly incomprehensible at the moment. It does not make it clear what  is even for, let alone how it works or how to use it. — This, that, and the other (talk) 00:55, 30 December 2010 (UTC)
 * I hope the section as it now stands works better than the old one.--Kotniski (talk) 11:56, 26 February 2011 (UTC)

includeonly
The page says "Use  in place of plain subst:. The includeonly tags break up the substitution syntax when the template is saved, but those tags will be stripped away when it is later substituted, allowing the inner substitution to take effect." I've tried this and it doesn't work. It made appear as plain text.  McLerristarr &#124;  Mclay1  09:14, 25 February 2011 (UTC)
 * Are you sure? I've just tried it (at User:Kotniski/Sandbox and then subst'ing at User:Kotniski/1) and it seems to work. --Kotniski (talk) 11:13, 25 February 2011 (UTC)
 * I tried it on User:Mclay1/Sandpit and User:Mclay1/Sandpit 2.  McLerristarr &#124;  Mclay1  04:50, 26 February 2011 (UTC)
 * So it should work, as long as you do the "subst:" in Sandpit 2. (It won't work on transclusion, as explained elsewhere on the page, although you could use "safesubst:" in place of "subst:" in Sandpit to give the same result at Sandpit 2 even on transclusion.)--Kotniski (talk) 11:59, 26 February 2011 (UTC)
 *  McLerristarr &#124;  Mclay1  14:49, 28 February 2011 (UTC)

Safesubst: is jargon loaded
To me the explanation of safesubst:, while it may be right, it isn't very helpful. It uses jargon and packs it in so tight that I cannot work out what it is saying or meaning. That being the case if there is no other means to explain it, then we should look to examples. If we could look to clearly state when it should be used, and what makes it "safe" that would be great. 112.213.156.24 (talk) 12:44, 12 April 2011 (UTC)

subst:PAGENAME versus subst::PAGENAME
I was never able to get subst:PAGENAME to work. Then I found this:

http://www.mediawiki.org/wiki/Help:Templates#Usage

Which mentions using subst::PAGENAME with two colons instead of one. That worked for me, and is apparently undocumented on any page (wikipedia, mediawiki, wikimedia, or metawiki) that is dedicated to documenting substitution. Is it just me, or is having documentation spread out across 4 different sites a contributing factor for poor documentation in general, and of substitution in particular?

Badon (talk) 19:08, 12 September 2011 (UTC)
 * It's an old question but for interested readers,  works on "Template:PAGENAME" while   works on the mainspace page "PAGENAME". It's like normal transclusion where   transcludes a mainspace page instead of a template. It's mentioned in Help:Substitution and was also there in 2011. PrimeHunter (talk) 15:34, 28 September 2022 (UTC)

Clarify Help:Substitution
I don't understand the limitation, in particular, the second sentence of Help:Substitution. I'd like to use subst inside a ref on or  to get 29 January 2016 or 29 January 2016 Reading it, I have no idea why this limitation exists (is it a feature, bug or both?), and what will do. It does this outside of a ref: ... Oh I think I get it, now that I try to explain how I don't get it.

I guess I can do substitution inside the "content of the reference", e.g.

I guess  will expand the templates and then place that expanded text within ref tags. Result:.

OK, so how to clarify? The example given needs to use subst. I gave it a try. Glad User:Carfois added it a year ago. -- Elvey (t•c) 01:12, 29 January 2016 (UTC)

Much of this is unclear and needs to be reworked by a technical writer
Could someone who understands this material in depth, and who has good technical writing skills, please overhaul everything from the "Recursive substitution" section though "Limitation" (aside from "Documenting substitution", which is clear)?

I can only make sense of about 60% of that material, despite being intelligent, a systems and network administrator and Web coder since the mid-90s, a Wikipedian for over 10 years, and a template-editor almost since that bit was introduced (and an editor of templates the whole time). It's basically written like a man page from the pre-GNU days, a crib sheet for people who are already experts at what the documentation is about.

It needs a table of common uses cases and example code and output that show entire templates, not fragments. I can't even tell if there's a way to have a template work fine if transcluded, work fine if subst'd, and subst "cleanly" and recursively (i.e. leave plan content behind with no  stuff in the page for the next editor) if it is subst'd. The doc talks about all of these aspects in different places and in inconsistent terms, without ever just answering the question directly, even though it must be a common one.

Also trying to figure out if there's a way to get templates to subst themselves automatically (I know can have them save with subst: in them so they'll at least do it the next time the section or the whole page is saved, but it would be advantageous for them to be forcibly substituted sometimes, without having to throw up melodramatic red warnings. If not, is there a bug open to fix it? I can't check; I have never been able to login to PHabricator; it always throws an LDAP error at me, and of course I can report this bug because I can't login).

For my work, the immediate need is to ensure that single-source templates are subst'd, cleanly. My rede on this is that the best we can do is document that they should be subst'd, and include code such that, if they are not, they include subst code when saved, so that the next time the page or section is saved it will be subst'd. (We could include a huge red warning instead, but that seems overkill for something that trivial). — SMcCandlish ☺ ☏ ¢ ≽ʌⱷ҅ᴥⱷʌ≼  11:28, 21 March 2016 (UTC)
 * If substitution could be forced, we'd set this up for templates like etc. - but we can't. -- Red rose64 (talk) 17:55, 22 March 2016 (UTC)
 * Was hoping there was some "secret trick".  — SMcCandlish ☺ ☏ ¢ ≽ʌⱷ҅ᴥⱷʌ≼  20:33, 22 March 2016 (UTC)

not supporting ref names?
doesn't seem to support s.

Example:

works all right:

But I want to put the ref name as. I tested using  instead:

but it adds ref name tags at the start and end of the citation:

What is the code to add only the  at the start and the closing tag only at the end of the citation? Thanks. Sanglahi86 (talk) 10:34, 17 October 2016 (UTC)


 * Looking at Help:Magic words, the syntax should be...

...with the name moved to the end. A quick test: there's a reference defined here and used again here. -- John of Reading (talk) 11:13, 17 October 2016 (UTC)


 * Thank you very much for the information. Sanglahi86 (talk) 13:07, 17 October 2016 (UTC)

Why is Subst leaving conditional cruft after transclusion
( If this is not the right forum in which to post a question about writing a subst'ed conditional template, please point me to the right place.)

I'm a new template writer, and when I subst a template I thought that one of the benefits was that all the conditionals and magic words and other such things get removed, leaving whatever they generate: plain text, wikilinks, and so on. But I'm transcluding my new template and it's leaving some pretty ugly stuff in the expanded wikicode. The rendering on the page looks just fine, it's just the wikicode that is ugly, but I thought that stuff was supposed to all just disappear.

Template:x2 review help is a template designed for user talk pages, and generates an invitation to join our translation project. It's mostly boilerplate that just gets plonked onto the user talk page, but there are some params to conditionally generate text, like what language we're talking about, and a few others. It also generates the Section title, and even *that* has an #ifexpr in it; very ugly.

Am I doing something wrong? Is there a way to just generate plain text, and get rid of all the ugly conditional code? An example of the template in use is available at User:Mathglot/sandbox/test Farsi x2 review. Feel free to alter that page to run further tests if needed. I'd love to know what I'm doing wrong.

Thanks in advance! Mathglot (talk) 03:57, 31 May 2017 (UTC)


 * Hey! It looks like you're after recursive substitution. I recently made an edit to a similar template for almost the same thing. If you give me a few minutes, I'll make an edit to your template that should sort things out. :) TheDragonFire (talk) 06:04, 31 May 2017 (UTC)


 * Wow, I never thought of that, good catch! Plus I'm learning something.  Very kind of you to fix the template for me, while you're doing that, I'll read up on recursive substitution.  Thanks again!  Mathglot (talk) 06:09, 31 May 2017 (UTC)


 * I see you've made an edit; wasn't sure if you were done or not; I notice an "unrecognized '{'" in the test in my sandbox:  #Test 2.  I might be able to locate it, or are you still busy with the template?  Mathglot (talk) 06:40, 31 May 2017 (UTC)
 * Yeah, I've partially reverted my changes as something is breaking with the article section. Feel free to keep editing the template, I'll fix it to fully use recursive substitution when I figure out what I'm doing wrong. TheDragonFire (talk) 06:46, 31 May 2017 (UTC)


 * I can't thank you enough for what you've already done. Way more complex than I thought, and will have to read through it carefully to try to understand.  Almost all the cruft is gone, *especially* the junk in the section title, which was really important.  I can certainly live with it like this, in case it ends up being too much of a time-waster to track down the last bit of it, and I thank you again. Mathglot (talk) 06:48, 31 May 2017 (UTC)

TLDR version for dummies?
Can someone just tell me what I actually need to know about subst in order to not fuck up when I use it? Something like ''When you see subst:, it means the template is going to substitute one thing for another for you. Just copy the whole damn thing and insert it where it belongs. You don't have to make any changes.'' Or what? I don't have the technical knowledge to be able to understand this page. —valereee (talk) 13:13, 5 September 2020 (UTC)
 * This stems from a conversation on my talk page. I responded there before noticing this message. Graham 87 13:37, 5 September 2020 (UTC)

Substituting templates after they already have been transcluded
Is there a way to easily replace with  in all pages? WP:AWB can do that, but it's quite complicated for what's basically just one bit of information, especially since it's something we want to encourage. ◅ Sebastian 08:59, 5 November 2020 (UTC)
 * If the consensus is that a particular template should always be substituted in future, then see Template:Always substitute. If you add  to the template documentation, then a bot will make sure they get cleaned up. -- John of Reading (talk) 09:57, 5 November 2020 (UTC)
 * Cool, thanks! That's a very sensible solution. ◅ Sebastian 16:07, 5 November 2020 (UTC)
 * What about adding  to the template documentation in TemplateData?--BoldLuis (talk) 14:49, 16 November 2022 (UTC)

Cleanup
There are quite a few cases of failed substitution within references that need to be cleaned up, found with {{sl|insource:/\{\{subst:/ -insource:"Anchor comment" -insource:"rfd"}}. Letcord (talk) 18:32, 2 April 2022 (UTC)

Why not just have a tag whose content is removed by subst:, so it is only displayed if the template is transcluded? (a functionality somewhat similar to and )

This way, you can display a big ugly warning to the user who misses the subst:, add the page to a special category or whatever you want. Much less intrusive than the other proposed changes.

From T4003 BoldLuis (talk) 14:47, 16 November 2022 (UTC)
 * You already brought this up at Help talk:Template - please observe WP:MULTI. -- Red rose64 &#x1f339; (talk) 17:17, 16 November 2022 (UTC)

A complex safesubst'ing job
has been deprecated since 2010 (pending various conditions, which were never met), but limps along anyway. Worse, the community deprecated all inline parenthetical referencing in 2022, but is dependent on, which is a form of (partial) inline parenthetical referencing. We need a way to cleanly subst into its constituent p parts, so that further replacement work can be done, e.g. with  or some other solution.

I've copied the current code of into, and done the same with its substemplates, and changed the sandbox code of all of them to refer to the sandbox versions of the subtemplates. This could use attention from someone already skilled in the pitfalls of getting complex templates to substitute cleanly without leaving behind conditional garbage and other problems. — SMcCandlish ☏ ¢ 😼  17:08, 22 January 2024 (UTC)