Difference between revisions of "Template:Get Element Types"

From OIAr Archive 2013
Jump to navigation Jump to search
(start)
 
(updated search and explanation)
 
Line 1: Line 1:
 
<noinclude>
 
<noinclude>
 
[[Category:Templates]]
 
[[Category:Templates]]
This template only serves to find all element types for a given page. It is called with only one parameter:
+
This template only serves to find all element types for a given page - it doesn't print them. It is called with only one parameter ''page'':
 
<pre><nowiki>
 
<pre><nowiki>
 
{{Get Element Types|page=}}</nowiki></pre>
 
{{Get Element Types|page=}}</nowiki></pre>
 
After calling this template, there exist two arrays (using [http://www.mediawiki.org/wiki/Extension:ArrayExtension extension ArrayExtension]):
 
After calling this template, there exist two arrays (using [http://www.mediawiki.org/wiki/Extension:ArrayExtension extension ArrayExtension]):
* Array "Cats", containing all categories that ''page'' is a member of (with a comma as delimiter)
+
* Array "Cats", containing all categories that ''page'' is a member of;
* Array "ElementTypes", containing the types of element that the ''page'' is a member of (stripped of the prefix "Element type" and with a comma as delimiter)
+
* Array "ElementTypes", containing the types of element that the ''page'' is a member of (stripped of the prefix "Element type")
 
Thus, if page ''EL.Example'' is a member of categories ''FooBar, Element type foo, Element type bar'', then<br>  
 
Thus, if page ''EL.Example'' is a member of categories ''FooBar, Element type foo, Element type bar'', then<br>  
Cats=''FooBar, Element type foo, Element type bar''<br>
+
Cats=''FooBar,Element type foo,Element type bar''<br>
ElementTypes=''foo, bar''
+
ElementTypes=''foo,bar''
 +
After calling this template, you can access the categories and Element Types using the [http://www.mediawiki.org/wiki/Extension:ArrayExtension#arrayprint #arrayprint] function. An example that creates a pretty, comma delimited list:
 +
<pre><nowiki>{{#arrayprint:ElementTypes||@ |@ |print=pretty}}</nowiki></pre>
 
----
 
----
</noinclude><includeonly>{{#arraydefine:Cats|{{#show:{{{page}}}|?Category|link=none|sep=,}}|,|unique}}{{#arraydefine:ElementTypes}}{{#arrayprint:Cats||@@@@|<nowiki/>{{#switch:{{#sub:@@@@|0|13}}|Element type ={{#ifeq:{{#arraysize:ElementTypes}}|0|{{#arraydefine:ElementTypes|{{#sub:@@@@|13}}}}|{{#arraydefine:ElementTypes|{{#arrayprint:ElementTypes|,}},{{#sub:@@@@|13}}}}}}}}}}
+
</noinclude><includeonly>{{#arraydefine:Cats|{{ShowCategories|page={{{page}}}}}|,|unique}}{{#arraysearcharray:ElementTypes|Cats|/^Element\stype\s/|0|-1|{{#sub:$0|13}}}}

Latest revision as of 11:55, 29 December 2012

This template only serves to find all element types for a given page - it doesn't print them. It is called with only one parameter page:

{{Get Element Types|page=}}

After calling this template, there exist two arrays (using extension ArrayExtension):

  • Array "Cats", containing all categories that page is a member of;
  • Array "ElementTypes", containing the types of element that the page is a member of (stripped of the prefix "Element type")

Thus, if page EL.Example is a member of categories FooBar, Element type foo, Element type bar, then
Cats=FooBar,Element type foo,Element type bar
ElementTypes=foo,bar After calling this template, you can access the categories and Element Types using the #arrayprint function. An example that creates a pretty, comma delimited list:

{{#arrayprint:ElementTypes||@ |@ |print=pretty}}