|
blog.sub_categories |
|
blog.sub_categories is a loop that is used to generate a list of subcategories of the currently viewed category.
The basic syntax of the article.categories loop is:
{{loop blog.sub_categories}}
(body of loop goes here)
{{/loop}}
The loop does one iteration for each subcategory of the current category. For example, if the currently viewed category has the subcategories Archery, Books and Gardening, the loop will go through Archery, then Books, then Gardening.
Within the blog.sub_categories loop, you can use these variables, whose contents change with each iteration:
| • | label |
The label of the subcategory for the current iteration. The label of a subcategory is the name that is displayed to the blog reader.
| • | path |
The path for the subcategory for the current iteration.
| • | url |
The URL of the page for the subcategory for the current iteration.
blog.sub_categories can also be used as a boolean variable. It is true if the current category contains at least one subcategory.
Example
Here is an example blog.sub_categories loop:
{{if blog.sub_categories}}
<h3>This category has the following subcategories:</h3>
<ul>
{{loop blog.sub_categories}}
<li><a href="{{url}}">{{label}}</a></li>
{{/loop}}
</ul>
{{/if}}
If the current category contains the subcategories Archery, Books and Gardening, the output of the above loop would look like this:
This article was posted under the following categories:
| • | Archery |
| • | Books |
| • | Gardening |
In the example above, each category is linked to the corresponding category page.
If the current category does not contain any subcategories, nothing is displayed.