Skip to content

Commit 6abd6f8

Browse files
fix!: don't override Kirby's default routing by default
1 parent e606b23 commit 6abd6f8

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Here are scenarios where the Kirby Headless plugin is particularly useful:
3434
Detailed instructions on how to use these features can be found in the [usage](#usage) section.
3535

3636
> [!TIP]
37-
> Kirby Headless overrides the global Kirby routes for the [templates](#templates) feature. To opt-out, head over to the [setup](#setup) section.
37+
> Kirby Headless doesn't interfere with Kirby's default routing. You can install it without affecting your existing Kirby site.
38+
> To use the [JSON templates](#templates) feature, opt-in to [override the gobal routing](#setup).
3839
3940
## Requirements
4041

@@ -57,20 +58,25 @@ Download and copy this repository to `/site/plugins/kirby-headless`.
5758

5859
## Setup
5960

60-
By default, the plugin will override the global Kirby routes and add its [own global routes](./src/extensions/routes.php) and [API routes for KQL](./src/extensions/api.php).
61+
> [!TIP]
62+
> If you don't intend to use the [JSON templates](#templates) feature, you can skip this section!
63+
64+
By default, the plugin doesn't interfere with Kirby's default routing, it just adds API routes like [for KQL](./src/extensions/api.php).
6165

62-
If you prefer the traditional Kirby frontend and only need headless functionality like KQL, you can disable the global routes in your `config.php`:
66+
To transform Kirby from a traditional frontend to a truly headless-only CMS, you have to opt-in to custom global routing in your `config.php`:
6367

6468
```php
6569
# /site/config/config.php
6670
return [
6771
'headless' => [
68-
// Disable overriding the global routes
69-
'routes' => false
72+
// Enable returning Kirby templates as JSON
73+
'globalRoutes' => true
7074
]
7175
];
7276
```
7377

78+
This will make all page templates return JSON instead of HTML by [defining global routes](./src/extensions/routes.php).
79+
7480
## Usage
7581

7682
### KirbyQL
@@ -180,10 +186,10 @@ return [
180186

181187
### Templates
182188

183-
Create templates just like you normally would in any Kirby project. Instead of writing HTML, we build arrays and encode them to JSON. The internal route handler will add the correct content type and also handles caching (if enabled).
189+
Write templates as you would in any other Kirby project. But instead of returning HTML, they return JSON. The internal route handler adds the correct content type and also handles caching (if enabled).
184190

185-
> [!TIP]
186-
> Kirby Headless overrides the global Kirby routes for this feature. To opt-out, set the `headless.routes` option to `false` in your `config.php`.
191+
> [!INFO]
192+
> Kirby Headless doesn't interfere with Kirby's default routing. To opt-in, follow the [setup instructions](#setup).
187193
188194
<details>
189195
<summary>👉 Example template</summary>

index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class_alias(\Kirby\Cms\Field::class, \Kirby\Content\Field::class);
2424
'api' => require __DIR__ . '/src/extensions/api.php'
2525
];
2626

27-
if ($kirby->option('headless.routes', true)) {
27+
// Register global routes, if enabled
28+
if ($kirby->option('headless.globalRoutes', false)) {
2829
$extensions['routes'] = require __DIR__ . '/src/extensions/routes.php';
2930
}
3031

0 commit comments

Comments
 (0)