Assets in content path

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:

The question is, is it possible to get a url more like the actual page url, like the one shown below:

Any help much appreciated.


        return $kirby->url() . '/' . $file->parent()->id() . '/' . $file->filename();

should work as well

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?

When called with something like this:

 <img src="<?=$page->cover()->resize(600,null,65)->url() ?>"
        srcset="<?=$page->cover()->srcset('bookcover') ?>"
        sizes="(min-width: 640px) 320px, 50vw"
        alt="<?=$page->cover()->caption()<>'' ? $page->cover()->caption(): ($page->title()->excerpt(120)) ?> cover"/>

Yes, you are not using images here, but File::Version objects, aka thumbs. And they are created in the media folder, never in the content folder.

To serve them from a different location, you therefore need to create a custom the File::Version component.

Or maybe something like this here: Permalinks for resized images - #3 by texnixe

Thanks texnixe, I shall investigate further.