Help talk:Substitution

From Meta, a Wikimedia project coordination wiki

The following section is beyond portability to w:Help:Substitution, therefore I've moved it here. Please make sure that new help pages work elsewhere. Something like "substitution" will sooner or later get tons of project specific links on w:en:, therfore it must work there. We have already three pages identified as FUBAR (soft redirect from w:en:), adding more to this collection is no good idea. It undermines the complete help system by frustrating readers and editors. -- Omniplex (w:t) 16:12, 12 May 2006 (UTC)[reply]

Rewriting a template that calls other templates in a self-contained form[edit]

If a template calls other templates one may want to rewrite it in a self-contained form (i.e., which does not need other templates) in order to use a copy of it in another project, without copying more templates.

For example, Template:t2a1 containing "{{t2demo|a|{{{1}}}}}", calling Template:t2 containing "Parameter 1 is "{{{1}}}", parameter 2 is "{{{2}}}"<noinclude>[[Category:Demo template]]</noinclude>", could be written "start-a-middle-{{{1}}}-end".

To do this semi-automatically, one cannot use subst without specifying a parameter, or with {{{1}}} as parameter: the result of that is like the template page "t2a1" shows: "start-a-middle-{{{1}}}-end". In fact this is how the confusing rendering of a template page can be analysed.

Instead, one can apply subst with parameter "{{{1}.}.}." and obtain "{{t2|a|{{{1}.}.}.}}". If we now remove the three dots again, we have the content of "t2a1" in a self-contained form: "start-a-middle-{{{1}}}-end".

Portability[edit]

At some stage w:User:Pioneer-12 suggested to forget about portability of the template help pages because it is cumbersome due to example templates [1]. I agree, and this applies also to a few other help pages such as this one.--Patrick 23:43, 12 May 2006 (UTC)[reply]

Anyway, Template:Ph:Substitution is for Meta-specific content.--Patrick 00:12, 13 May 2006 (UTC)[reply]

Seen today (missed on watchlist): IMO we need more clear and simple recipes "if you want this do that", and less "if you do this you get that". Some notorious demo templates {{tc}}, {{3X}}, and one or two more are fine, we could declare them to be "handbook templates" required together with copies of pages like Substitution.
But not dozens of obscure templates, undocumented, uncategorized, unclear purpose, unless somebody tries to edit them, and the code happens to be "obvious". For unlikely values of "obvious" as "after reading and understanding template + advanced template + substitution + calculation + array + magic words + colon function + variables". Nobody will ever do this. Please don't count me in as counterexample. -- Omniplex (w:t) 01:02, 24 June 2006 (UTC)[reply]

I think these templates t, t1, t2, 3X, and more are quite convenient. They are very simple, and help pages use them repeatedly to demonstrate something.--Patrick 02:14, 24 June 2006 (UTC)[reply]

Forced substitution[edit]

Rescued from Template talk:O, that's a kind of sandbox unless an experiment produces something useful, when it could be moved to a better name:

If a template requires subst: it does not need a parameter {{{subst}}}, it can use subst: with includeonly for inner templates.--Patrick 22:16, 23 June 2006 (UTC)[reply]

So far I don't understand this technique. Ideally I'd like to get a recipe does A if subst'ed, else B. -- Omniplex (w:t) 01:02, 24 June 2006 (UTC)[reply]

Distilled/Summary Version?[edit]

Has anyone produced a distilled version of this information or a nice, quick summary so that the average (or slightly above-average) editor can understand what they can easily get out of substitution? There's obviously a lot of power here, but it's tough to digest in terms of how it can be useful.

I added a section.--Patrick 09:13, 27 September 2006 (UTC)[reply]


Odd quirk noted when subst not used[edit]

I edit the English language Wikipedia and I noticed an odd quirk with one of the templates for user talk pages. See the template talk for the Welcomespam template; I don't know if this is unique to this one template or if it's true of all templates. --69.241.131.62 11:46, 28 October 2006 (UTC) (A. B.)[reply]

This is normal, see Help:Section#Editing_sections_of_included_templates. If it is not desired, do not put a header in the template, but put it manually before calling the template.--Patrick 15:58, 28 October 2006 (UTC)[reply]

Limitation with subst and for loop?[edit]

This could be a limitation, my misunderstanding, and/or improvement to the help text... which?

The idea was when creating a new page, one might want to create it with the following text, and have all information subst from each included template below it:

{{ subst:Create Page Skeleton|John|Jane|Sally|Susi|...etc...}}

Using a For loop inside of Create Page Skeleton, this should create a page with static content that has 4 modules on it, one for John, Jane, Sally, Susi. (If there were more parameters, it would create more modules.)

I can't seem to get subst to work on the for loop and at each level thereafter. I can get it to work without subst. (Below is the working version without subst.)

I've tried various (if not random at times) versions of optional (subst=subst:) and delayed (<noinclude>subst:</noinclude>) substitution but can't seem to make it work. Limitation or user error?

Here is an example loop without using subst:

Template:Create Page Skeleton contains:

<!-- This page was created using subst:Create Page Skeleton|A|B|C|D|...etc... -->

Welcome to our page. Here are the modules for each person:

{{ foreach/mypass1

   |{{{1|@}}}|{{{2|@}}}|{{{3|@}}}|{{{4|@}}}|{{{5|@}}}...etc...{{{150|@}}}

   |v@=

   |c=Template:Module

}}

<!-- end of template -->

Template:Module contains:

<!-- header -->{{ MyModuleHeader }}<!-- get contents page -->{{ {{FULLPAGENAME}}/{{{1}}} }}<!-- footer -->{{ MyModuleFooter }}

<!-- end of template -->

Template:foreach/mypass1 contains something like:

<!--

-->{{{{{{{{v{{{1|}}}|c}}}|x0}}}|1={{{1}}}}}<!--

-->{{{{{{{{v{{{2|}}}|c}}}|x0}}}|1={{{2}}}}}<!--

-->{{{{{{{{v{{{3|}}}|c}}}|x0}}}|1={{{3}}}}}<!--

-->{{{{{{{{v{{{4|}}}|c}}}|x0}}}|1={{{4}}}}}<!--

-->{{{{{{{{v{{{5|}}}|c}}}|x0}}}|1={{{5}}}}}<!--

etc...

-->{{{{{{{{v{{{150|}}}|c}}}|x0}}}|1={{{150}}}}}

<!-- end of template -->

Template:x0 is empty

Can the above example be made to work with subst for all levels? The goal is to support (with simple top-level construct) user-created pages with a variable number of specified modules under it.

I think that due to Help:Substitution#Parameter_default_considerations a for loop cannot work with subst.--Patrick 01:12, 19 November 2006 (UTC)[reply]

Subst that gives the value of a parameter?[edit]

Is it possible to write a template that called this way: {{subst:templatename|hello}} gives hello in the edit form? --Nicolamr 18:53, 30 December 2006 (UTC)[reply]

Template:X1.--Patrick 20:37, 30 December 2006 (UTC)[reply]

Thank you but sorry: I forgot a part of the question: Is it possible to write a template that called this way: {{subst:templatename|hello}} gives hello in the edit form, but if I call it this way {{subst:templatename}} it gives nothing or a predefined value in the edit form? --Nicolamr 17:33, 31 December 2006 (UTC)[reply]

Yes, it is explained in Help:Substitution#Parameter_default_considerations:
Instead of {{{p|q}}} one can use {{{{{subst|}}}#ifeq:{{{p|+}}}|{{{p|-}}}|{{{p}}}|q}}, with substitution and subst=subst: this results in the wikitext q if p is undefined.
Patrick 02:11, 1 January 2007 (UTC)[reply]

Translation[edit]

How can I translate "subst" for another language wikipedia where the language should be right-to-left. 70.49.158.107 23:19, 31 March 2007 (UTC)[reply]

It seems that as usual "subst:" comes to the left of the template name.--Patrick 00:39, 1 April 2007 (UTC)[reply]
I know and I can have used it this way. My question is can I translate it for another language wikipedia? 70.49.158.107 05:09, 1 April 2007 (UTC)[reply]
It is in the message file, e.g. in MessagesHe.php:
'subst' => array( 0, 'ס:', 'SUBST:' ),
This allows both the use of 'ס:' and 'SUBST:'. --Patrick 11:24, 1 April 2007 (UTC)[reply]
See also MediaWiki_localisation#Submit_patch.--Patrick 11:33, 1 April 2007 (UTC)[reply]

Wiktionary[edit]

An example of substitution in Wiktionary, to automatize the creation of sections with translation items:

Template_talk:trans10

--Mac 10:51, 16 June 2007 (UTC)[reply]

question[edit]

w:Wikipedia:Template substitution includes a list of templates on en.wikipedia that should and should not be substituted. Does an analogous list for templates on meta exist somewhere? Specifically, shouldn't {{support}} and {{oppose}} always be substituted since they are used often and in discussions? Dar-Ape 19:29, 28 November 2007 (UTC)[reply]

I don't think there is such a list here. @2nd question: Imho the benefit from the oppose or support templates are to save typing {{oppose}} instead of '''oppose'''(to type {{subst:oppose}} is much longer) +they contain an icon for non English speakers. Another disatvantage I fear is that the source code is getting harder to read with substituted voting templates: e.g. oppose would look like {{#switch:{{BASEPAGENAME}}|Requests for new languages=Oppose|[[Image:Symbol oppose vote.svg|15px]] '''Oppose'''}} Best regards, --birdy geimfyglið (:> )=| 23:13, 28 November 2007 (UTC)[reply]

this documentation is very unclear[edit]

  • There's no simple example showing usage. The very first example is the meaningless {{subst:#expr:2*{{{p|3}}}}}
  • The overview starts with a theoretical background instead of editor-centric "Here's what this solves" motivation.
  • In the very first sentence "Substitution is automatic conversion of wikitext of a page referring to a template...", it's completely unclear what "referring" refers to: conversion, wikitext, the page itself, ???

-- skierpage 03:11, 9 April 2008 (UTC)[reply]

I clarified the third point.--Patrick (talk) 23:28, 6 December 2009 (UTC)[reply]

optional substitution[edit]

There is no "optional substitution" header, which is referenced by a link in the page itself and from other pages. Please re-add the header, or fix the link. 202.36.205.226 01:08, 22 July 2008 (UTC)[reply]

Indeed. The dox no longer make sense. — SMcCandlish [talk] [cont] ‹(-¿-)› 16:17, 1 September 2008 (UTC)[reply]
I fixed the link.--Patrick (talk) 23:18, 6 December 2009 (UTC)[reply]

Main Namespace Substitution[edit]

Is there a known way to use 'subst:' when pulling in a page from the main namespace? I've tried the obvious choice ( {{subst::PageToInclude}} ) but that doesn't work. Speed8ump 14:58, 13 October 2008 (UTC)[reply]

I tried it and it works.--Patrick (talk) 23:23, 6 December 2009 (UTC)[reply]

Article template substitution[edit]

I am trying to create a template that is used to start new articles but where there is a substitution for the date, in an essence adding a time stamp within the article. How would I do that? 83.177.85.37 19:24, 15 May 2012 (UTC)[reply]

Work on this page[edit]

Just a note: I saw some work on this page at mw:User:Mindrones/Manual:Substitution. I may check it out later.--Patrick (talk) 10:17, 30 August 2012 (UTC)[reply]

subst errors reporting?[edit]

Where (here?) can I announce/ask for errors of subst parsing {{subst:#time:Y-m-d}} (no substitution!) - see f.e. 1 and 2 (they're after Visual editor & then Code editor use) --Segu (talk) 17:17, 8 August 2017 (UTC)[reply]

add channel 54[edit]

Please add channel 54... My address is 16105 Eucalyptus Ave. Apt6... Bellflower, Ca. 90706 Gfyshiloh (talk) 18:15, 17 December 2017 (UTC)[reply]

Overloading subst: in template namespace for hiding wikitext during expansion?[edit]

During the substitution phase I assume the mw software just skips any tokens that don't start with {{subst: or {{safesubst:

During expansion however, does the parser skip these items completely or would it be possible (and very hack-y) to create a template with "subst:" or "safesubst:" at the beginning of the template name which gets expanded during page rendering?

To give an example:

  1. Suppose Template:XYZ is designed to only work as intended when used with subst: or safesubst:
  2. Template:XYZ also uses a few tricks of recursive substitution to write {{subst:XYZ}} to the wikitext when saved.
  3. As noted in Help:Recursive conversion of wikitext however, the call to {{subst:XYZ}} will render as text output in the page unless it is suppressed with something like display: none; CSS rules or similar.
  4. But suppose you were to also create a template named Template:subst:XYZ ... 😈 😱
  5. The contents of Template:subst:XYZ could be completely empty or have an html comment that doesn't render.
  6. Would Template:subst:XYZ be detected and rendered as empty during expansion and Template:XYZ also be used to replace wikitext during substitution??

Thanks if anyone knows this. N8wilson (talk) 00:16, 19 March 2022 (UTC)[reply]