Go to page content


Reasoning with the category hierarchy

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

A category is a page with a special category record attached to it. This category record is used to organize the tree of categories.

The m_category model provides accessors to this category tree and individual category information.

An example of a category tree, as returned by m.category.tree:

  {path,{ok,[]}}], … ]

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.

tree1Return the root element of all category trees.
tree2Return the root set and their direct children as category trees.
all_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 tuples {CategoryId, Level, NbspLevel, CategoryName}  The list does not contain the “meta” category, which contains the categories “predicate”, “category” etc.[…, {106, 2, "&nbsp;&nbsp;&nbsp;&nbsp;", <<"article">>}, … ]
all_flat_metaSame as all_flat but now including the meta category.

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:

PropertyDescriptionExample value
treeThe category tree below and including the indexing category.See above.
tree1The list of direct children below the indexing category.[ [{id,106}, {parent_id,104}, {seq,3}, {nr,3}, {lvl,2}, {lft,3}, {rght,4}, {name,<<"article">>}, {path,{ok,"h"}}], … ]
tree2The category tree below and including the indexing category, up to the children of the chidren.See above.
pathList of parent categories from the root till the category, excluding the indexing category.[ 104, 106 ]
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
lvlThe depth of the category. Level 1 is the root, 2 and more are below the root.1
lftThe lowest value of the nr range of this category, including its sub categories.


rghtThe 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.{ok, [104, 106]}

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.