Forum template tags
Board / TemplateTagsThis documentation explains the templatetags provided by the Board application.
You need to {% load sphboard_extras %} to use them.
1. Display all available categories
It might be useful to display a hierarchical list of the forum categories - e.g. for a "jump to forum" select box or similar. This can be done using the sphboard_recursive_category_iterator template tag.
1.1. Usage
The content between sphboard_recursive_category_iterator and endsphboard_recursive_category_iterator will be taken and rendered for every category in the hierarchy. In each iteration the context will be filled with the following template variables:
- category: the current Category object.
- children: the rendered children of this category (if you do not include this in your template, only the root categories will be rendered)
- depth: an integer representing the current depth in the hierarchy (starting with 0)
- depthrange: can be used in a for loop, for example to display "-" for every step in the hierarchy.
1.2. Example
The following example displays a simple select box which will jump to the selected forum as soon as the value is changed.
{% load sphboard_extras %}
<select name="category" onchange="if(this.value) document.location = this.value;" class="sphboard_selectcategory">
<option value="">Jump to category</option>
<option value="">------------------</option>
{% sphboard_recursive_category_iterator %}
<option value="{{ category.get_absolute_url }}">{% for i in depthrange %}--{% endfor %} {{ category.name }}</option>
{{ children }}
{% endsphboard_recursive_category_iterator %}
</select>
2. Display the latest threads of one category
You probably want to list the latest threads of a category e.g. on the start page or in the base template on one side of your website (something like 'latest news', etc.) - If you are not using the Wiki, this template tag is for you.
2.1. Usage
Simply pass in the ID for the category for which you want to display the latest threads. You probably want to use a settings variable for this, so you don't have a hardcoded ID in your templates. (but feel free to do it any other way)
2.2. Example
{% load sphboard_extras %}
{% sphboard_latest_threads sph_settings.groups_sphene_news_category_id %}
{% for post in threads %}
<h2>{{ post.postdate|sph_date:"ONLY_DATE" }}</h2>
<p><a href="{{ post.get_absolute_url }}">{{ post.subject }}</a></p>
<p>{{ post.body_escaped }}</p>
{% endfor %}
{% endsphboard_latest_threads %}
Tags:
Last Modified: 2009-08-13 23:01:34 by Herbert Poul - [ Snip Changes ] [ Wiki History ]
0 Comments
No comments yet.
Please login to create a new thread.