m_category

  • Module: core

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,{ok,[]}},
  {name,<<"other">>},
  {path,{ok,[]}}],
 [{id,104},
  {parent,undefined},
  {level,1},
  {children,{ok,[[{id,106},
                  {parent_id,104},
                  {level,2},
                  {children,{ok,[[{id,109},
                                  {parent_id,106},
                                  {level,3},
                                  {children,{ok,[]}},
                                  {name,<<"news">>},
                                  {path,{ok,...}}]]}},
                  {name,<<"article">>},
                  {path,{ok,"h"}}],
                 [{id,105},
                  {parent_id,104},
                  {level,2},
                  {children,{ok,[]}},
                  {name,<<"review">>},
                  {path,{ok,"h"}}],
                 [{id,503},
                  {parent_id,104},
                  {level,2},
                  {children,{ok,[[{id,504},
                                  {parent_id,503},
                                  {level,3},
                                  {children,{ok,...}},
                                  {name,<<...>>},
                                  {path,...}]]}},
                  {name,<<"documentation">>},
                  {path,{ok,"h"}}]]}},
  {name,<<"text">>},
  {path,{ok,[]}}], …
]

About the complete category tree

The following m_category model properties are available in templates:

Property Description Example value
tree Return the complete forest of category trees as nested property lists. See above.
tree1 Return the root element of all category trees.  
tree2 Return the root set and their direct children as category trees.  
all_flat Return 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_meta Same 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:

{{ m.category[104].tree }}
{{ m.category.text.tree }}
Property Description Example value
tree The category tree below and including the indexing category. See above.
tree1 The 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”}}], … ]
tree2 The category tree below and including the indexing category, up to the children of the children. See above.
path List of parent category ids from the root till the category, excluding the indexing category. [ 104, 106 ]
is_a List of the parent category names form the root till the category, including the current category. [ text, article, news ]
image A 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_id The page id of the parent category. Returns an integer or, for a root category, undefined. 104
nr The category nr. Used for building the tree, will change when categories are added or removed. An integer. 2
lvl The depth of the category. Level 1 is the root, 2 and more are below the root. 1
lft The lowest value of the nr range of this category, including its sub categories. 2
rght The highest value of the nr range of this category, including its sub categories. 8
name The unique page name of this category. A binary. <<”text”>>
path The path through the hierarchy of categories to this category. {ok, [104, 106]}

Table Of Contents

Previous topic

m_backup_revision

Next topic

m_comment

Versions

Actions