Template:Wikipedia Link/Documentation: Difference between revisions

From Soul's Remnant Wiki
Jump to navigation Jump to search
(Created page with "This template took a slightly embarassing amount of time to make but it's pretty easy to explain: <nowiki>{{wl|Source text|Wikilink}}</nowiki> <nowiki>{{wl|Example}}</nowiki> Renders as: {{wl|Source text|Wikilink}} {{wl|Example}} with (on wikipedia) linking to wikipedia:Wikilink in the first case, and wikipedia:Example in the second case. ==How it works (the headache inducing code== The exact code under the hood is actually pretty simple but it's still a mes...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{Documentation top}}
This template took a slightly embarassing amount of time to make but it's pretty easy to explain:
This template took a slightly embarassing amount of time to make but it's pretty easy to explain:


Line 11: Line 13:
with (on wikipedia) linking to [[wikipedia:Wikilink]] in the first case, and [[wikipedia:Example]] in the second case.
with (on wikipedia) linking to [[wikipedia:Wikilink]] in the first case, and [[wikipedia:Example]] in the second case.


==How it works (the headache inducing code==
==How it works (the headache inducing code)==
The exact code under the hood is actually pretty simple but it's still a mess of symbols. But I can summarize it here.
The exact code under the hood is actually pretty simple but it's still a mess of symbols. But I can summarize it here.


Line 26: Line 28:
Finally, we use <nowiki>}}</nowiki> to close out the if block, <nowiki>]]</nowiki> to close out the link, <nowiki>)</nowiki> to close out the visible parentheses, <nowiki></small></nowiki> to close out the small text block, and <nowiki></includeonly></nowiki> to indicate the end of the relevant section.
Finally, we use <nowiki>}}</nowiki> to close out the if block, <nowiki>]]</nowiki> to close out the link, <nowiki>)</nowiki> to close out the visible parentheses, <nowiki></small></nowiki> to close out the small text block, and <nowiki></includeonly></nowiki> to indicate the end of the relevant section.


{{for documentation}}
{{documentation bottom}}

Latest revision as of 23:49, 28 October 2025

Template:Documentation top

This template took a slightly embarassing amount of time to make but it's pretty easy to explain:

{{wl|Source text|Wikilink}} {{wl|Example}}

Renders as:

Source text (on Wikipedia) Example (on Wikipedia)

with (on wikipedia) linking to wikipedia:Wikilink in the first case, and wikipedia:Example in the second case.

How it works (the headache inducing code)

The exact code under the hood is actually pretty simple but it's still a mess of symbols. But I can summarize it here.

The <includeonly> tags allow me to isolate the template to only the relevant section, and leave the rest under <noinclude> so it doesn't bother the rest of the template. So we only focus on the bit inside:

Start with {{{1}}}, which simply parrots back the first field, in these example case, "Source Text" and "Example".

Next, the <small> small tag indicates that the tag should be in small text.

Next, we open a link with [[wikipedia:, indicating that we would like to make a cross-wiki link to an article on Wikipedia.

Next, we use the {{#if {{{2|}}}| block to test if the second field exists. If it does, we link to the second field. In the first case, this means we resolve the link to Wikilink, which we do with the second component: {{{2}}}. If it does not exist, we assume that the link is the same in both places, so we simply link the link text, using {{{1}}}.

Finally, we use }} to close out the if block, ]] to close out the link, ) to close out the visible parentheses, </small> to close out the small text block, and </includeonly> to indicate the end of the relevant section.

Template:Documentation bottom