Skip to content
poxd edited this page Oct 16, 2010 · 17 revisions

Categories Manager

Identifies all the defined categories and populates node.categories with a list of dictionaries containing:

  • name : the name of the category
  • posts : the list of posts belonging to the category
  • feed_url : the url category’s feed
  • post_count : the number of posts in the category

Optionally, it can also generate the post listing by category basing on a template that you provide.

Configuration

The example below populates categories for the blog node. blog.categories will contain the list of dictionaries. It also generates the posts’ listing by category basing on the template _archives.html (shown below) into the folder archives (which is the default but is defined here for the sake of the example). It finally adds also an index.html into the archives folder based on the _archives_index.html (shown below) template defined here to the processor by the key listing_template.


SITE_PRE_PROCESSORS = {
    'blog': {
        'hydeengine.site_pre_processors.CategoriesManager' : {'node': 'blog', 'template': '_archives.html', 'output_folder': 'archives', 'listing_template': '_archives_index.html'},
    },
}

_archives.html

{%hyde
    listing: true
%}
<div id="archives">
<ul>
{% for post in posts %}
    {% ifchanged post.created.year %}
    <li><h1 class="section">{{post.created|date:"Y"}}</h1></li>
    {% endifchanged %}
    <li class="entry">
        <div><span class="postdate">{{post.created|date:"j/m"|title}}</span></div>
        <div><a href="{{post.url}}">
        {% with post.name_without_extension|remove_date_prefix|unslugify as default_title %}
            {% filter typogrify %}
            {{post.title|default_if_none:default_title }}
            {% endfilter %}
        {%endwith%}</a></div>
    </li>
{% endfor %}
</ul>
</div>

<div class="sidebar">
<h1>Categories</h1>
{% for category in categories|dictsort:"name" %}
<li><a href="{{category.archive_url}}">{{category.name}}</a></li>
{% endfor %}
</div>

As you can see the posts variable — the collection of posts in the current category — is provided to the template. In addition the categories is also provided as a shortcut to the list of dictionaries (see Categories Manager section). The Category object is defined in site_pre_processors.py.

_archives_index.html

The ‘listing_template’ template receives the categories variable on which you can loop to reference every category defined on your blog.


<h1>List of categories</h1>
<ul>
  {% for c in categories %}
  <li><a href="{{c.archive_url}}">{{c.name}}</a></li>
  {% endfor %}
</ul>

Node Injector

Injects a node identified by the given path as the value of the given context variable for all the pages in the specified node.

Configuration

The following configuration injects the blog node (/content/blog) as blog_node variable into all the pages in the content folder.


SITE_PRE_PROCESSORS = {
    '/': {
        'hydeengine.site_pre_processors.NodeInjector' : {
               'variable' : 'blog_node',
               'path' : 'content/blog'
        }
    }
}
Clone this wiki locally