Building a site
Routing
In Lapis, you do not register routes. The files in pages/ are the routes, as in Next.js: a file's path is its URL, [name] in a file name is a parameter, and [...name] takes the rest of the path.
pages/
index.php /
contact.php /contact
blog/
index.php /blog
[slug].php /blog/{slug}
You can list the routes of a site, with their methods and middleware, at any time:
./lapis routes
Files and URLs
The following table shows every kind of route file:
| File | URL | Note |
|---|---|---|
pages/index.php |
/ |
static |
pages/contact.php |
/contact |
static |
pages/blog/index.php |
/blog |
static |
pages/blog/[slug].php |
/blog/{slug} |
needs a page record |
pages/blog/[slug].post.php |
the same | for pages of type post |
pages/docs/[...path].php |
/docs/… |
catch-all, needs a page record |
pages/_types/landing.php |
any path | template of landing pages |
pages/_404.php |
(none) | 404 page |
pages/_maintenance.php |
(none) | 503 page while ./lapis down is active |
Files and folders whose name starts with _ are never routes. Lapis uses them for special files, such as _404.php, _maintenance.php, _types/ and _middleware.php.
How a URL finds its file
When a request comes in, Lapis looks for the most specific file first. Static routes win over [param] routes, those win over [...catchall] routes, and longer paths win over shorter ones.
A static route needs no record in the database. One is created when an editor first changes something on the page.
A dynamic route only matches when there is a page record for the path. Visitors see published pages, editors see pages of any status. When a page record has no route file of its own, _types/{type}.php renders it, if that template exists.
Page types
Every page has a type, page by default. The types are declared in lapis.config.php, and editors choose one when they create a page. For a dynamic match, Lapis picks the template in this order:
[slug].{type}.php, next to the matching route,_types/{type}.php,[slug].php.
One page, its own template
To give a single page its own template, create a file with its slug, such as pages/about.php. To give a group of pages a shared template, give them a type and create [slug].{type}.php or _types/{type}.php.
Some pages have no page record at all, for example a product page built from a data table. Such a template uses a #[Get] loader, which decides whether the page exists. See Page functions. A page file may also answer POST and other methods, or be a route file without a template, such as a feed or an API.