You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-5Lines changed: 22 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -271,21 +271,38 @@ A middleware checks if a `Authentication` header is set, which is not the case i
271
271
272
272
### `resolvePermalinks()`
273
273
274
-
This field method resolves page and file permalinks to their respective URLs. It is primarily intended for usage with KQL queries, because the value of `writer` fields contain permalink URLs like `/@/page/nDvVIAwDBph4uOpm`. But the method works with any field that contains permalinks in `href` attributes.
274
+
This field method resolves page and file permalinks to their respective URLs. It is primarily intended for usage with KQL queries, because the value of `writer` fields contain permalink URLs like `/@/page/nDvVIAwDBph4uOpm`. But the method works with any field values that contains permalinks in `href` or `src` attributes.
275
275
276
-
In multilanguage setups, you may want to remove a language prefix like `/de` from the URL. You can do so by defining a custom path parser in your `config.php`:
276
+
For headless usage, you may want to remove the origin from the URL and just return the path. You can do so by defining a custom URL parser in your `config.php`:
277
277
278
278
```php
279
279
# /site/config/config.php
280
280
return [
281
281
'permalinksResolver' => [
282
-
// Strip the language code prefix from the URL for German
283
-
'pathParser' => function (string $path, \Kirby\Cms\App $kirby) {
282
+
// Strip the origin from the URL
283
+
'urlParser' => function (string $url, \Kirby\Cms\App $kirby) {
284
+
$path = parse_url($url, PHP_URL_PATH);
285
+
return $path;
286
+
}
287
+
]
288
+
];
289
+
```
290
+
291
+
Or in multilanguage setups, you may want to remove a language prefix like `/de` from the URL:
292
+
293
+
```php
294
+
# /site/config/config.php
295
+
return [
296
+
'permalinksResolver' => [
297
+
// Strip the language code prefix from German URLs
298
+
'urlParser' => function (string $url, \Kirby\Cms\App $kirby) {
@@ -176,7 +183,7 @@ function ($matches) use ($kirby, $pathParser) {
176
183
*
177
184
* @kql-allowed
178
185
*/
179
-
'toResolvedBlocks' => function (\Kirby\Content\Field$field) use ($pagesFieldResolver, $filesFieldResolver, $customFieldResolver, $nestedBlocksFieldResolver) {
186
+
'toResolvedBlocks' => function (Field$field) use ($pagesFieldResolver, $filesFieldResolver, $customFieldResolver, $nestedBlocksFieldResolver) {
180
187
return$field
181
188
->toBlocks()
182
189
->map($nestedBlocksFieldResolver)
@@ -190,7 +197,7 @@ function ($matches) use ($kirby, $pathParser) {
190
197
*
191
198
* @kql-allowed
192
199
*/
193
-
'toResolvedLayouts' => function (\Kirby\Content\Field$field) use ($filesFieldResolver, $pagesFieldResolver, $customFieldResolver) {
200
+
'toResolvedLayouts' => function (Field$field) use ($filesFieldResolver, $pagesFieldResolver, $customFieldResolver) {
194
201
return$field
195
202
->toLayouts()
196
203
->map(function (\Kirby\Cms\Layout$layout) use ($filesFieldResolver, $pagesFieldResolver, $customFieldResolver) {
0 commit comments