When genrating some static pages with kirby, we’d like to have the assets linked to the folder they are in rather than linked to the media folder. To do that we used the example of the ‘Assets in Content’ plugin, a summary of the index.php is below:
use Kirby\Cms\App as Kirby;
Kirby::plugin(‘name/assets-in-content', [
'components' => [
'file::url' => function (Kirby $kirby, $file) {
return $kirby->url() . '/content/' . $file->parent()->diruri() . '/' . $file->filename();
},
]
]);
This gives a link to the asset something like this: https://domain.net/content/1_books/20210725_book-name/book.epub
The question is, is it possible to get a url more like the actual page url, like the one shown below: https://domain.net/books/book-name/book.epub
Many thanks texnixe, that is brilliant. Static assets are pathed correctly, but images still seem to link to media? I presume there is a reason for this?
The idea was to keep some files, like ebooks, in the actual page content folder as far a url was concerned. Previously this worked, I don’t know which version that was, but it doesn’t work in the latest version.
So this url worked:
domain/books/book/book.epub
but it does not now -404 Not Found
If I remove the plugin the files appear but now from the media folder.
domain/media/pages/books/book/xxxx/book.epub
Thanks very much Sonja for your efforts, I have been doing this upgrade for some time, so I can’t actually remember, maybe v3 of Kirby? The site is now updated and works well locally apart from this bit and I need it to work because of the URL links to epubs and some other stuff on the pages.
As ever Sonja, many thanks, I would have never found that . I don’t remember it from the original, perhaps older Kirby versions were different? But then it was some time ago and I may have forgotten. Anyway it is just what was required and now everything works as it should, so thanks again for your awesome support!