Difference between revisions of "Template:DiscoverParents"

From AtlasWiki
Jump to: navigation, search
(reverting to working version)
(re-applying change to support multiple namespaces, with a fix making the parameter optional, resulting in no output unless a parameter is provided.)
Line 22: Line 22:
 
Next, we split up our input parameters into an array.
 
Next, we split up our input parameters into an array.
  
--></noinclude>{{#arraydefine:children|{{{1}}}|, |}}<noinclude><!--
+
--></noinclude>{{#arraydefine:children|{{{1|}}}|, |}}<noinclude><!--
  
 
Then, we find the parents of each child, storing them in an array.
 
Then, we find the parents of each child, storing them in an array.
Line 35: Line 35:
 
There's one remaining small issue: in a few cases we can end up with both "page" and "XCSG:page" in the results, so we need to define a new array to eliminate that issue...
 
There's one remaining small issue: in a few cases we can end up with both "page" and "XCSG:page" in the results, so we need to define a new array to eliminate that issue...
  
--></noinclude>{{#arraydefine:simplified|{{#arrayprint:parents|,|@@@@|{{TrimNamespace|@@@@}}|}}|,|unique}}<noinclude><!--
+
--></noinclude>{{#arraydefine:simplified|{{#arrayprint:parents|,|@@@@|{{EnsureNamespace|@@@@}}|}}|,|unique}}<noinclude><!--
  
Finally, print out our simplified list of parents with namespaces removed.
+
Finally, print out our simplified list of parents with the XCSG namespace removed, but leaving other namespaces and parenthetical disambiguators intact.
  
--></noinclude>{{#arrayprint:simplified|,|@@@@|@@@@}}<noinclude>[[Category:XCSG Templates]]</noinclude>
+
--></noinclude>{{#arrayprint:simplified|,|@@@@|{{#arraydefine:namespaceTest|@@@@}}{{#ifeq:{{#arrayindex:namespaceTest|0}}|XCSG|{{#arrayindex:namespaceTest|1}}|@@@@}}}}<noinclude>[[Category:XCSG Templates]]</noinclude>

Revision as of 13:17, 22 May 2014

This template is designed to help in discovering distinct parents that can be reached over "extends" relationships among XCSG elements within a specific number of inheritance steps.

Note that the results of this template will always include the parameters, and will always trim off the XCSG namespace from both inputs and results.

For example: {{DiscoverParents|{{PAGENAME}}}} should return a comma-separated list of parents of the current page, which also includes the current page itself. {{FULLPAGENAME}} instead should produce exactly the same results.

{{DiscoverParents|{{DiscoverParents|{{PAGENAME}}}} should find all parents and grandparents, with each listed only once in case a diamond pattern occurs, and will again include the current page itself.

To avoid including the current page, combine use of this template with the Template:ParentsOf template:

{{DiscoverParents|{{ParentsOf|{{FULLPAGENAME}}}}}} will return two levels of parents of

This template can also be used to find the union of the parents of two or more unrelated XCSG nodes or edges, for example, this query would find the union of the parents and grand-parents of X and Y: {{DiscoverParents|{{ParentsOf|X}}, {{ParentsOf|Y}}}}