Help talk:Substitution
This is the talk page for discussing improvements to the Substitution page. |
|
This help page does not require a rating on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | |||||||||||
|
Why substitute?
[edit]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 Wikipedia:Template substitution. Dar-Ape 19:21, 28 November 2007 (UTC)
Template with substitution and subsequent transclusion
[edit]I am trying to build a template that includes the title of the page that is using the template. Simple enough, use:
{{FULLPAGENAME}}
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
{{subst:FULLPAGENAME}}
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:
<includeonly>{{subst:FULLPAGENAME}}</includeonly>
The result of that, however, is to literally display "{{subst:FULLPAGENAME}}" 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 --> {{subst:UC:{{subst:FULLPAGENAME}}}} (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 {{<includeonly>subst:</includeonly> FULLPAGENAME}} , for a working example (for now) see User:Unomi/hex. un☯mi 10:51, 19 August 2010 (UTC)
Clarify
[edit]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
[edit]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 {{subst:User:Unomi/hex}} should be only the result of the evaluation, not having the logic embedded on the page, Many thanks in advance, un☯mi 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 un☯mi 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 . un☯mi 11:58, 19 August 2010 (UTC)
- Does
{{Dec2hex}}
do what you want? --Redrose64 (talk) 12:35, 19 August 2010 (UTC)- Lovely! Thanks! :) un☯mi 12:42, 19 August 2010 (UTC)
- Does
I now see there is also {{Hexadecimal}}
, when it rains it pours I guess :) un☯mi 12:49, 19 August 2010 (UTC)
Substituting only the template output
[edit]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 {{Time|CET}} template)? /HeyMid (contributions) 12:14, 4 September 2010 (UTC)
- See m:Help:Substitution#Multilevel substitution.--Patrick (talk) 13:17, 4 September 2010 (UTC)
- I don't get it. Could you try and subst {{Time}} without all the nonsense (e.g. only the context output) here? /HeyMid (contributions) 13:52, 4 September 2010 (UTC)
- Not sure what you want here. I have looked at User:Heymid/Test, and I see this:
{{[[Template:Time|Time]]}}
- To create a link to a template, without transcluding it, you don't need to do this; just prefix the template name with
tl|
, ie{{tl|time}}
, which yields {{time}}. There's a whole family of these, such as{{tlx}}
. --Redrose64 (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. /HeyMid (contributions) 18:16, 4 September 2010 (UTC)
- Like here (done with {{subst:Time}}. 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 {{subst:Time}} 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 {{{1}}}, {{{2}}} variable or to a named attribute?
- 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. /HeyMid (contributions) 18:16, 4 September 2010 (UTC)
- Not sure what you want here. I have looked at User:Heymid/Test, and I see this:
- I don't get it. Could you try and subst {{Time}} without all the nonsense (e.g. only the context output) here? /HeyMid (contributions) 13:52, 4 September 2010 (UTC)
- Take my above questions one by one. /HeyMid (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
[edit]I would like to make a template, say ABCD which has to take CURRENTDAY as a mandatory parameter. So the use of {{ABCD}} is not permitted, but users should use {{subst:ABCD}}. Now, if some user uses {{ABCD}} in an article, it should display the message Please use {{subst:ABCD}} instead of the template {{ABCD}}. 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
{{subst:WikiProject England}}
. It's partly done with the{{substcheck}}
template, also some code in{{WPBannerMeta}}
. --Redrose64 (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. --Redrose64 (talk) 13:40, 30 December 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)
- You can use something like
{{#if:{{{{{|subst:}}}ns:0}}|transcluded|substituted}}
- Patrick (talk) 16:42, 30 December 2010 (UTC)
safesubst section does not make sense
[edit]Could someone who understands safesubst:
please rewrite that section of the page? It is utterly incomprehensible at the moment. It does not make it clear what safesubst:
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
[edit]The page says "Use <includeonly>subst:</includeonly>
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 {{subst:PAGENAME}} appear as plain text. McLerristarr | 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 | 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)
- Thank you McLerristarr | Mclay1 14:49, 28 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)
- I tried it on User:Mclay1/Sandpit and User:Mclay1/Sandpit 2. McLerristarr | Mclay1 04:50, 26 February 2011 (UTC)
Safesubst: is jargon loaded
[edit]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
[edit]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,
{{subst:PAGENAME}}
works on "Template:PAGENAME" while{{subst::PAGENAME}}
works on the mainspace page "PAGENAME". It's like normal transclusion where{{:PAGENAME}}
transcludes a mainspace page instead of a template. It's mentioned in Help:Substitution#Syntax and was also there in 2011. PrimeHunter (talk) 15:34, 28 September 2022 (UTC)
Clarify Help:Substitution#Limitation
[edit]I don't understand the limitation, in particular, the second sentence of Help:Substitution#Limitation. I'd like to use subst inside a ref on {{TODAY}} or {{Date}} 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 {{safesubst:#tag:ref|content of the reference}} will do. It does this outside of a ref: [1]... 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 {{safesubst:#tag:ref|{{subst:TODAY}} or {{subst:Date}}}} will expand the templates and then place that expanded text within ref tags. Result: [2] .
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
[edit]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 {{#if:{{{foo|}}}}}
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
{{subst:uw-vandalism1}}
etc. - but we can't. --Redrose64 (talk) 17:55, 22 March 2016 (UTC)- Was hoping there was some "secret trick". — SMcCandlish ☺ ☏ ¢ ≽ʌⱷ҅ᴥⱷʌ≼ 20:33, 22 March 2016 (UTC)
#tag:ref
not supporting ref names?
[edit]#tag:ref
doesn't seem to support ref name
s.
Example:
{{#tag:ref|{{cite web |title=Municipality/City: {{safesubst:#invoke:Wikibase|label|{{safesubst:#invoke:Wikidata|pageId}}}} |url=http://nap.psa.gov.ph/activestats/psgc/municipality.asp?muncode={{str_sub|{{safesubst:#Property:P988}}|0|6}}000®code={{str_sub|{{safesubst:#Property:P988}}|0|2}}&provcode={{str_sub|{{safesubst:#Property:P988}}|2|2}} |work=PSGC Interactive |publisher=Philippine Statistics Authority |accessdate={{safesubst:TODAY}} |location=Makati City, Philippines}}}}
works all right:
But I want to put the ref name as nscb
. I tested using #tag:ref name="nscb"
instead:
{{#tag:ref name="nscb"|{{cite web |title=Municipality/City: {{safesubst:#invoke:Wikibase|label|{{safesubst:#invoke:Wikidata|pageId}}}} |url=http://nap.psa.gov.ph/activestats/psgc/municipality.asp?muncode={{str_sub|{{safesubst:#Property:P988}}|0|6}}000®code={{str_sub|{{safesubst:#Property:P988}}|0|2}}&provcode={{str_sub|{{safesubst:#Property:P988}}|2|2}} |work=PSGC Interactive |publisher=Philippine Statistics Authority |accessdate={{safesubst:TODAY}} |location=Makati City, Philippines}}}}
but it adds ref name tags at the start and end of the citation:
<ref name="nscb">"Municipality/City:". PSGC Interactive. Makati City, Philippines: Philippine Statistics Authority. Retrieved 17 October 2016.</ref name="nscb">
What is the code to add only the ref name
at the start and the closing </ref> tag only at the end of the citation? Thanks. Sanglahi86 (talk) 10:34, 17 October 2016 (UTC)
References
- ^ "Municipality/City:". PSGC Interactive. Makati City, Philippines: Philippine Statistics Authority. Retrieved 17 October 2016.
- @Sanglahi86: Looking at Help:Magic words#Formatting, the syntax should be...
{{#tag:ref|{{cite web |title=Municipality/City: |url=http://nap.psa.gov.ph/activestats/psgc/municipality.asp?muncode={{str_sub||0|6}}000®code={{str_sub||0|2}}&provcode={{str_sub||2|2}} |work=PSGC Interactive |publisher=Philippine Statistics Authority |accessdate=17 October 2016 |location=Makati City, Philippines}}|name=nscb}}
...with the name moved to the end. A quick test: there's a reference defined here [1] and used again here [1]. -- 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
[edit]This help request has been answered. If you need more help, you can , contact the responding user(s) directly on their user talk page, or consider visiting the Teahouse. |
(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)
- @Mathglot: 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)
- @TheDragonFire: 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)
- @TheDragonFire: 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)
- @Mathglot: 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)
- @TheDragonFire: 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?
[edit]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. Graham87 13:37, 5 September 2020 (UTC)
Substituting templates after they already have been transcluded
[edit]Is there a way to easily replace {{template...}} with {{subst:template...}} 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)
- @SebastianHelm: If the consensus is that a particular template should always be substituted in future, then see Template:Always substitute. If you add
{{Always substitute|auto=yes}}
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
alwayssubst=yes
to the template documentation in TemplateData?--BoldLuis (talk) 14:49, 16 November 2022 (UTC)
- What about adding
- Cool, thanks! That's a very sensible solution. ◅ Sebastian 16:07, 5 November 2020 (UTC)
Cleanup
[edit]There are quite a few cases of failed substitution within references that need to be cleaned up, found with insource:/\{\{subst:/ -insource:"Anchor comment" -insource:"rfd". Letcord (talk) 18:32, 2 April 2022 (UTC)
<nosubst>
[edit]Why not just have a tag <nosubst> whose content is removed by subst:, so it is only displayed if the template is transcluded? (a functionality somewhat similar to <noinclude> and <includeonly>)
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 phab:T4003 BoldLuis (talk) 14:47, 16 November 2022 (UTC)
- You already brought this up at Help talk:Template#.3Cnosubst.3E - please observe WP:MULTI. --Redrose64 🌹 (talk) 17:17, 16 November 2022 (UTC)
A complex safesubst'ing job
[edit]{{R}}
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 {{r}}
is dependent on {{rp}}
, which is a form of (partial) inline parenthetical referencing. We need a way to cleanly subst {{r}}
into its constituent <ref>...</ref>
{{rp}}
parts, so that further replacement work can be done, e.g. with {{sfnp}}
or some other solution.
I've copied the current code of {{r}}
into {{r/sandbox}}
, 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)