Treeview extension

From FollowTheScore
Revision as of 23:25, 8 September 2007 by Nad (talk | contribs) (Creating Category Trees)
Jump to: navigation, search

This demonstrates the use of the Treeview extension

Treeview can produce clickable tree lists. The interesting thing is that the input for Treeview can either be defined statically or can be derived from a DPL query.


The following images are used in Treeview:   plus plus   minus.gif minus   arrow-Closed.png arrow-Closed   arrow-Open.png arrow-Open   Folder Folder   Folder-Open FolderOpen   Document Doc   Spacer (Spacer)

Example (static definition of items)

Treeview recognizes lines which start with one or more asterisks just like the mediawiki parser does when it is looking for bullet point lists:

{{#tree:
*A
**A1
**A2
***A21
***A22
**A3
*B
}}

As a result you will get a clickable tree: {{#tree:

  • A
    • A1
    • A2
      • A21
      • A22
    • A3
  • B

}}

Generating a Simple List as a Tree with DPL

The simplest example of using DPL with the tree-view would be for creating single level lists such as the titles in a given category. If we want the listed items to appear inside a root item, then they must be preceded by double asterisks. The following example makes a list of all the articles in Category:Cities:

{{#tree:openlevels=1|
*'''Cities'''
{{#dpl:category=Cities|format=,**,[[%PAGE%]]\n,}}
}}

{{#tree:openlevels=1|

}}

Generating Simple Tree Views with DPL

Treeviews can be generated by DPL, as in the following example. We define a Template called Template:Links 1 which expects

  • the direction of the links (outgoing="from" or incoming = "to")
  • the source page
  • an optional name for the source page

Now we can write something like:

 {{#tree:{{Links 1|from|Wgraph}}}}
               or
 {{#tree:{{Links 1|to|Wgraph|references to the ''Wgraph homepage''}}}}

which will give us two menu trees, one for each direction: {{#tree:


}}


{{#tree:


}}

Generating Advanced Tree Views with DPL

Using nested DPL statements we can even produce a menu which shows more than one level of linkage references. Although this can be solved generally with a recursive template we prefer to have an explicitly named template for two levels.

 {{#tree:{{Links 2|from|Wgraph}}}}
           and
 {{#tree:{{Links 2|to|Wgraph}}}}

This will produce the following tree menus: {{#tree:


}}


{{#tree:


}}

Note that Template:Links 2 uses a special notation to represent double curly braces and a special pipe symbol to separate template arguments:

²{subQuery¦parameter¦..}²

This is needed because we must defer the evaluation of subQuery to a moment in time where the DPL result of the first (outer) query has already been calculated. This is necessary because we want to use %PAGE% and %TITLE% as part of the argument list for subQuery.

DPL has a built-in replacement mechanism which will convert the special characters ²{,}² and ¦ to their normal counterpart at the appropriate moment. This is a very powerful feature as is allows recursive calls between DPL statements. See the DPL:Manual - General Usage and Invocation Syntax.

Creating Category Trees

I made a template called Template:CatTree which also depends on Template:CatTreeSub and works in a similar way to Template:Links 2 and Template:Links 2.1 above, but makes the tree from categories and sub-categories instead, for example here's a category tree starting at Category:Countries.

{{CatTree|Countries}}

{{#tree:openlevels=1|



}}