With this field plugin for Kirby 2 you can display the list of subpages in the main column of the panel. Simply add the new field „subpagelist” to your blueprints.
With this plugin I basically wanted to level up my Kirby skills (learning by doing). It is inspired by this topic by thguenther. If you have any tipps or suggestions, please contact me.
Add (if necessary) a new fields
folder to your site
directory. Then copy the whole content of this repository in a new folder called subpagelist
. Your directory structure should now look like this:
site/
fields/
subpagelist/
assests/
languages/
subpagelist.php
template.php
It is possible to add this plugin as a Git submodule.
$ cd your/project/root
$ git submodule add https://github.com/flokosiol/kirby-subpagelist.git site/fields/subpagelist
For more information, have a look at Working with Git in the Kirby blog.
Now you are ready to use the new field subpagelist
in your blueprints.
...
fields:
mysubpagelist:
label: My Subpagelist
type: subpagelist
...
There are some optional parameter, which change the display of the subpagelist
flip
– returns the subpages in reverse orderlimit
– adds pagination after x itemssortable
– if set toFALSE
sorting of subpages is removedsort
– sorts subpagelist by existing field, e.g. 'Date'. This is useful for news listing.
...
fields:
mysubpagelist:
label: Latest news
type: subpagelist
flip: true
limit: 32
sortable: false
...
...
fields:
mysubpagelist:
label: Latest news
type: subpagelist
flip: true
limit: 32
sort: date desc
...
For this to work, a field 'date' must exist in the blueprint of the subpages.
The parameter filter
needs some more configuration:
visible
– returns only visible pages if set toTRUE
and only invisible ones if set toFALSE
template
– filters by used (and not by intended) templatefield
– you can also filter by any other field of the subpages, the same as you would do using the filterBy function. Therefor you have to define thename
,value
and optionaly another value to be compared to (see examples below).
...
fields:
mysubpagelist:
label: My Subpagelist
type: subpagelist
filter:
visible: true
template: mytemplate
field:
name: description
value: *=
compared_to: test
...
This will filter all subpages which are visible
, use the template mytemplate
and have a field named description
containing (*=
) the string test
.
...
fields:
mysubpagelist:
label: My Subpagelist
type: subpagelist
filter:
field:
name: section
value: food
...
This will filter all subpages with a field named section
and containing the value food
.
To hide the subpages in the sidebar, simply add this to your blueprint (as described in the Kirby docs):
...
pages:
hide: true
...