Template talk:Autolink
Explanation[edit]
I'm actually planning to put a real template here soon. But in the process of testing this template on my test wiki I discovered an unexpected, weird bug; what the template "should" be displaying right now is:
- [[Template:{{{1}}}|{{{1}}}]]
But it isn't. After pulling my hair for two hours, convinced that I'd caused the bug and therefore needed to rip out large chunks of my code, I finally realized that my code wasn't to blame. This is what vanilla MW1.10 does (but MW1.14 has fixed it).
I saved this buggy template snippet on UESP (a) so that I could check what the template does on both content1 and content2 (content2's output proving that it's not even the other code I've written) and (b) so everyone else can see that this happens even if MetaTemplate is not installed. And perhaps confirm that I'm not going crazy....
To explain what's happening here:
- Before calling the #if parser function, wiki parses all of #if's arguments. But since {{{1}}} hasn't been defined, it doesn't replace that variable; it just leaves the {{{1}}} in place, as a semi-placeholder.
- #if does its processing, and decides that the result of the #if should be [[Template:{{{1}}}|{{{1}}}]].
- Before finishing up, though, #if tries once more to parse the resulting text. However, at this point {{{1}}} is defined: #if is a quasi-template and therefore the first argument to the #if function is {{{1}}}. Plus, {{{1}}} is the argument without stripping the whitespace (even though #if normally strips the whitespace). In other words, {{{1}}} is equivalent to "\n [[Template:{{{1}}}|{{{1}}}}]] ".
- Luckily the wiki only does one round of trying to expand this recursive mess.
In short, this only happens if you use {{{1}}} instead of {{{1|}}} and if you use numerical arguments in calls to parser functions.