-
Couldn't load subscription status.
- Fork 9
Pages Collection
A pages collection defines a list of pages based on a path and additional state filters. If you want to create a blog, a page collection is just what you need.
A collection is defined in the frontmatter of the page.
collection:
model: pages
state:
recurse: bool
level: int
path: url, '.'
visible: true
category: string
collection: bool
year: int
month: int
day: int
published: bool
page:
layout: stringNote: pages is a shortcut for the com:pages.model.pages identifier
- category: return pages from a specific category only. By default, the category is the name of the folder the pages are nested in.
- path: the base path to use for the collection, default is the path where the collection is defined in.
- visible: Indicates if the page should appear in the navigation or not
- recurse: Recurse child folders, default 1
- level: Maximum level to recurse, default 0
The page option sets the default global properties for all the pages in the collection. For example, it sets the default layout or visibility state for all pages in the collection.
- Layout: The layout allows you to specify the layout that should be used for each of the pages returned. The layout is only used if the page doesn't have it's own layout defined.
By default, files and folders are sorted alphabetically. But if you want to set a custom order for your files and folders, all you need is a .order.[format] file. Inside this file, you can specify the order of all the data files of a folder.
Let's say you have pages home.html.php, about.html.md, and contact.html.md. Without the .order file, the pages will be ordered alphabetically as:
* about.html.md
* contact.html.md
* home.html.php
But if we want the home page to go first, we could create a file called .order.yaml which contains the following:
- home.html.php
- about.html.md
- contact.html.md
The file types you can use for the order file are YAML, JSON, INI, PHP, and XML. The page ordering is not limited to files. You can order both files and folders.
- fileA.html.md
- fileB.html.md
- folder1
- folder2
The following example will render a list of the titles of the different posts. The files are fetched from the same folder as the page.
<ul>
<? foreach(collection() as $page): ?>
<li><?= $page->title ?></li>
<? endforeach ?>
</ul>
Got a question or need help? We have a forum on Github Discussions where you can get in touch with us.