Difference between revisions of "Template:PipeTrick"

From AtlasWiki
Jump to: navigation, search
(Created page with "<noinclude> This template creates a link that uses the pipe trick if and only if the pipe trick can be used. i.e., the pipe trick is valid to be used for a link such as [[XCS...")
 
(close parenthesis should have been open paranthesis)
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
<noinclude>
 
<noinclude>
This template creates a link that uses the pipe trick if and only if the pipe trick can be used.
+
This template emulates the "pipe trick", producing a link whose displayed text excludes the namespace (if any), and excludes everything after the first open parenthesis.
 
+
</noinclude>{{#arraydefine:colonSplit|{{{1}}}|:}}[[{{{1}}}|{{#switch:{{#arraysize:colonSplit}}| 1 = {{#explode:{{{1}}}|(|0}} | #default = {{#explode:{{#arrayindex:colonSplit|1}}|(|0}} }}]]
i.e., the pipe trick is valid to be used for a link such as [[XCSG:Node]], producing [[XCSG:Node|Node]] because the article is in a namespace.
+
 
+
Similarly, the pipe trick is valid to be used for a link such as [[DataFlow (Node)]], producing [[DataFlow (Node)|DataFlow]], because that page has a parenthetical disambiguation.
+
 
+
However, the pipe trick will not work for a link that does not have anything to remove, such as [[Node]], and adding a pipe will break the link, giving [[Node|Node]].
+
 
+
Since we can't always tell in templates whether a pipe trick is needed, this template can be called instead, to determine whether the pipe trick is possible, and produce a link with the pipe trick if it is, or without the pipe trick if attempting the pipe trick would break the link.
+
</noinclude>{{#arraydefine:colonTest|{{{#1|}}}|:}}{{#arraydefine:openParenTest|{{{#1|}}}|(}}{{#arraydefine:closeParenTest|{{#arrayindex:openParenTest|1}}|)}}{{#switch:{{arraysize:colonTest}}| 0= {{#switch:{{#arraysize:closeParenTest}}|0 = [[{{{1}}}]]| #default= [[{{{1}}}{{!}}]]}} | #default = [[{{{#1}}}{{!}}]]}}
+

Latest revision as of 16:21, 20 October 2015

This template emulates the "pipe trick", producing a link whose displayed text excludes the namespace (if any), and excludes everything after the first open parenthesis. [[{{{1}}}|{{{1}}}]]