Category Extension Draft #277
taufik-nurrohman
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a category extension documentation initiation.
This extension enables the category filter feature by using the page’s
kind
property to add multiple routes, such ashttp://127.0.0.1/blog/category/:category/1
, to each page to allow users to list all pages in the current folder by category.Panel extension can help you to automate everything. But if you have to, you can still make this extension work without the GUI feature. Before we start, you need to know how this extension works.
Writing a category file is the same as writing a page file. The only difference is that you have to write the
id
property separately from the page. Be sure to specify a unique number for eachid.data
file. These numbers will then be used to associate the category file with thekind
property on each page:Here’s an example of what a category file might contain:
To associate categories with the current page, create a
kind.data
file in the relevant folder that contains a list of category IDs written in a valid JSON format:Example contents of a
kind.data
file:Unlike tags, category IDs are written as a float to represent parent-child relationship because categories can also have several other associated sub-categories. Digits before the period denote the parent category ID, and digits after the period denote the current category ID. Category ID with prefix
0.
denotes a category without a parent. Therefore, ID0
should not be used. You should create a category ID starting with the number1
. Other integer values will be considered as tag IDs.You can also include the
kind
property in the page header, but this method may not be performance efficient when reading the data:Sub-categories are stored as child pages. This allows sub-categories to have the same name with a different parent page name:
Category child routes will then be available as follows:
Usage
These HTML classes will be added to the root element if it contains a
class
attribute when you are on the categories page. You can use this feature to create a specific look or response on your site from the client side if the following classes are found in the root element:is:category
: Will be added if the current items view is a category view and is not empty.
Example usage in CSS code:
Example usage in JS code:
These additional conditional statements are available for use in layouts to show/hide elements on your site from the server side:
$site->is('category')
: Returns
true
if the current items view is a category view and is not empty.Example usage in HTML/PHP code:
These additional variables are available for use in layouts that carry data related to the currently active category page:
$category
: This variable is an instance of the
Category
class, which you can use to get the current category information.Example usage in HTML/PHP code:
This extension will also add
category
property to the page only if the page contains akind
property thatis not empty:
Example usage in HTML/PHP code:
Beta Was this translation helpful? Give feedback.
All reactions