Difference between revisions of "Template:PipeTrick"

From AtlasWiki
Jump to: navigation, search
(removing #es)
(changed purpose...pipe trick doesn't work at all in templates, only in live editing...so this is a substitute for use by templates.)
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>[[{{{1}}}|{{explode:{{#explode:{{{1}}}|:|0}}|(|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}}}{{!}}]]}}
+

Revision as of 14:57, 12 May 2014

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}}}|{{explode:{{{1}}}|(|0}}]]