Creating pages
Pages can be created via the Panel, directly in the file system, or programmatically. If you create a new page via the Panel, it is always created as a draft. In the file system, you can create pages with any state directly.
Creating pages in the Panel
Before you can add new pages via the Panel, you have to set up a pages section in your page or site blueprint, with the status set to draft
or all
.
Click on the "Add" button in the top right corner of a pages section. Every new page in the Panel is created as a draft first. This prevents accidental publishing of a page that is not ready yet.
Drafts are stored in a _drafts
subfolder for every page. These drafts are only accessible when you are logged in.
If you want to automatically publish new pages created via the Panel, you can set up a page.create:after
hook in your config.php
file.
Duplicate existing pages
In the Panel, new pages can also be created by duplicating existing pages. This is great if you want to reuse parts of the content.
To do so, select "Settings" > "Duplicate". In the duplicate dialog, you can edit the title and URL slug, and decide if you want to copy all files as well. When done, confirm with the "Duplicate button". By default, Kirby adds "copy" to title and slug.
Creating published pages manually
Pages are stored as subfolders of the /content
folder. To create a new page manually, create a new folder and add a text file with the extension .txt
(default) or .md
(optional configuration setting).
A simple folder structure could look like this:
If you want to create a site with different languages using Kirby's built-in multi-lang feature, you need to add language code extensions for each language, e.g. home.en.txt
, home.de.txt
etc.
The naming of these content files is important, because it defines which template is used to render the content.
Content filename | Template filename |
---|---|
home.txt | home.php |
projects.txt | projects.php |
contact.txt | contact.php |
If there is no corresponding template, the default.php
template is used to render the page.
Each page folder is accessible via its URL, e.g. you can access the projects folder by entering the domain name followed by the UID of the folder into your browser's address bar: https://example.com/projects
. If your projects folder contains subpages, the subpage project-a
would therefore be accessible via https://example.com/projects/project-a
etc.
URLs can be modified using Kirby's router.
Creating drafts manually
If you want to create a draft manually in the content folder you can create a _drafts
subfolder in the parent page folder (if it's not there yet) and inside create your draft page folder.
Creating pages programmatically
Pages can also be created via Kirby's API methods in a controller, template, plugin, hook etc. This is useful if you want to create pages from form data, external files (like an Excel or .csv
file), or from an external API.
The basic syntax for creating a page using the $page->createChild()
method looks like this:
The above code only works if you are either logged in and have the necessary permissions for the action, or if you authenticate the user programmatically to perform the action Learn more about permissions and impersonating users.