category

This model can retrieve information about the resource category hierarchy in different ways.

Categories are the principal categorization (typing) system of resources. Every page is assigned to exactly one category. Categories themselves are organized in a tree-like hierarchy.

A category is a resource with a special category record attached to it to store metadata related to the category hierarchy. The m_category model provides accessors to this category tree and individual category information.

An example of a category tree, as returned by {% print m.category.tree %}:

[[{id,101},
  {parent_id,undefined},
  {level,1},
  {children,[]},
  {path,"e"},
  {left,1000000},
  {right,1000000}],
 [{id,104},
  {parent_id,undefined},
  {level,1},
  {children,[[{id,106},
              {parent_id,104},
              {level,2},
              {children,[[{id,109},
                          {parent_id,106},
                          {level,3},
                          {children,[]},
                          {path,"hjm"},
                          {left,4000000},
                          {right,4000000}]]},
              {path,"hj"},
              {left,3000000},
              {right,4000000}]]},
  {path,"h"},
  {left,2000000},
  {right,4000000}],
  ...]

About the complete category tree

The following m_category model properties are available in templates:

PropertyDescriptionExample value
treeReturn the complete forest of category trees as nested property lists.See above.
tree2Return the forest of category trees as nested property lists. Up to the children of the children.See above.
tree_flatReturn a list of tuples for the category tree. This list is intended for select lists. There is a special field for the indentation. The returned list consists of proplists. The list does not contain the "meta" category, which contains the categories "predicate", "category" etc.See above entries.
tree_flat_metaSame as tree_flat but with the categories in the meta category.See above entries.

About a single category

The m_category has some special properties defined when fetching a category, they are accessed by id or category name. For example:

{{ m.category[104].tree }}
{{ m.category.text.tree }}
PropertyDescriptionExample value
treeThe category tree below and including the indexing category.See above.
tree1The list of direct children below the indexing category.See above.
tree2The category tree below and including the indexing category, up to the children of the children.See above.
tree_flatThe category tree below and including the indexing category, up to the children of the children. As a flattened list.See above.
pathList of parent category ids from the root till the category, excluding the indexing category.[ 104, 106 ]
is_aList of the parent category names form the root till the category, including the current category.[ text, article, news ]
imageA random depiction for this category. The returned image filename comes from one of the pages within this category.<<"2009/10/20/flat-world-proof.jpg">>
parent_idThe page id of the parent category. Returns an integer or, for a root category, undefined.104
nrThe category nr. Used for building the tree, will change when categories are added or removed. An integer.2
levelThe depth of the category. Level 1 is the root, 2 and more are below the root.1
leftThe lowest value of the nr range of this category, including its sub categories.2
rightThe highest value of the nr range of this category, including its sub categories.8
nameThe unique page name of this category. A binary.<<"text">>
pathThe path through the hierarchy of categories to this category.[104, 106]

Available Model API Paths

MethodPath patternDescription
get/tree/...Return full category forest as nested hierarchy records (all non-meta roots and descendants).
get/tree2/...Return category forest in the limited tree2 representation (up to grandchildren level).
get/menu/...Return category forest formatted for menu rendering (hierarchy plus display metadata).
get/tree_flat/...Return flattened category list for selection UIs, excluding the meta branch.
get/tree_flat_meta/...Return flattened category list including the meta branch categories.
get/is_used/+cat/...Return whether any resource is assigned to +cat or one of its descendant categories.
get/+cat/path/...Return ancestor category id path for +cat; returns undefined when category is unknown.
get/+cat/is_a/...Return is_a ancestry (category names) for +cat; returns undefined when category is unknown.
get/+cat/tree/...Return nested subtree rooted at +cat; returns undefined when category is unknown.
get/+cat/tree_flat/...Return flattened subtree list rooted at +cat; returns undefined when category is unknown.
get/+cat/tree1/...Return direct-child tree level for +cat; returns undefined when category is unknown.
get/+cat/tree2/...Return subtree of +cat in tree2 format (up to grandchildren); returns undefined when unknown.
get/+cat/image/...Return a random depiction filename from resources in category +cat; returns undefined when category is unknown.
get/+cat/...Return category record for +cat (id/name/nr/level/left/right/parent metadata); returns undefined when unknown.

/+name marks a variable path segment. A trailing /... means extra path segments are accepted for further lookups.

Edit on GitHub