Hi! I've created a welcome template on Wikipedia, w:Template:PhyWelcome, but it doesn't work properly; the problem I'm experiencing is described in detail on w:Wikipedia talk:Welcoming committee/Welcome templates#Help with template, please!. I have no idea of what it is that is causing the problem. The template is basically just a modified copy of w:Template:MedWelcome, and that one is working just fine. I'm not used at all to MediaWiki's ParserFunctions (which the template contains), but I was hoping to get some help here.
Topic on Project:Support desk
So basically two things:
- When wiki-table syntax ({| type stuff) is used in templates, the |'s have to be replaced with {{!}}. This is in order to tell if the | means to end the {{#if or if its to end the table. |'s in links you don't have to worry about. You also don't have to worry about the |'s if the table is in its own template, unless that template is being substituted (see this diff)
- Subst: only works at save-time (what's technically called during pre-save-transform time). safesubst has to be used in cases where something may or may not be substituted. The difference between them is a bit complicated to understand, but any time you have something combining includeonly and subst, like
{{<includeonly>subst:</includeonly>foo}}
, you should probably be doing{{<includeonly>safesubst:</includeonly>foo}}
(This is because the template is substituted depending on if its being included or not, which can't be decided at pre-save-transform time, but must be decided at render time).- If in doubt, just use safesubst:, it will always work, where subst: only sometimes works (The reason both exist is mostly historical).
Cheers.
Thank you very much, both for the explanation and for the fix. I hadn't even thought of that inserting a table could mess things up, but of course that was it since it was basically the only drastic change I made. I will use {{!}} in templates that are supposed to be possible to nest inside of parser functions in the future, and also safesubst inside of <includeonly> tags.
I have another problem now. In the current state the PhyWelcome template is in, it works well and can correctly choose between PhyWelcome-reg and PhyWelcome-anon when it is just displayed, but as soon as I choose to substitute the template, it always chooses PhyWelcome-reg for some reason. If I on the other hand grab all code in the template and copy it to place manually, the correct template is chosen, so it seems like the template isn't really substituted when I use subst
, but something else, similar but not the same to a manual substitution, happens. I have included some
<includeonly>safesubst:<includeonly>
before #if:
, #ifeq:
and other miscellaneous templates that I want substituted; maybe this has something to do with it? Once again, I have really no idea of what could be wrong or how I should debug this. It doesn't really feel sane either to make a huge amount of Wikipedia edits just to find a bug in a template.
Hmm, apparently (after some debugging) when in subst mode, it was comparing a literal {{lc:{{BASEPAGENAME}}}}, not what you expect its value to be. You need to replace the {{lc:{{BASEPAGENAME}}}} with {{<includeonly>safesubst:</includeonly>lc:{{<includeonly>safesubst:</includeonly>BASEPAGENAME}}}} (and ditto for uc:{{BASEPAGENAME}} part.
Debugging templates can be hard. w:Special:expandtemplates and be useful, so can the api but both are kind of complicated to use if you're not already very familiar with how templates work. (In this case, I used var_dump on my local install, but that's generally not an option for most people ;)
Thanks! It seems to be working now, after inserting <includeonly>safesubst:</includeonly>
at some additional places.
By the way, how can I use the API? I would like to be able to do the same thing for other pages.
The api can be used to parse wikitext, so you get an idea of what a page will look like without saving.
For example:
http://en.wikipedia.org/w/api.php?action=parse&text={{safesubst:PhyWelcome}}&title=192.13.2.1&pst&format=xmlfm
Show's you the result of what {{safesubst:PhyWelcome}} on the page 192.13.2.1 would like, with doing pst.
http://en.wikipedia.org/w/api.php?action=parse&text={{safesubst:PhyWelcome}}&title=192.13.2.1&format=xmlfm
Show's you without pst. Without pst (pre-save-transform) is kind of like what it'd look like when included from a template (Esp for subst:), except that <includeonly> behaves as if it was directly on the page