Page links not working in text blocks

When I use the new K4 link field’s Page option inside a text block it doesn’t seem to work. Instead of returning the correct page URL, it returns a ‘coded’ URL that I assume is based on the page UID – e.g. http://localhost/@/page/7CsOtqaefmywv3XT. Local dev environment ovviously.) And when you click on the resulting link in the front-end, unsurprisingly it returns a ‘Not found’ error.

This only seems to be an issue when using the link field inside a text block. I assume it’s because the ->toUrl() method is not used. (I have used the link field in a homemade button plugin, where I can specify the ->toUrl() method in the button.php snippet and that works fine.)

Is there a way to make sure the ->toUrl() method is included when inside a text block? I know I can use the Custom option as a fallback but that’s not very client-friendly.

Thanks.

Right, this is a permalink to the page, but nevertheless it should go to the right page. If it doesn’t, then something is going wrong for some reason.

Another question is if you want these type of links or if you would rather convert them to normal page links. Then you would have to overwrite the block snippet for the text block and call the permalinksToUrls() field method on the field:

Hi, Sonja.

Regarding the permalink, I looked at the .txt content file for the relevant page and the UUID does match the reference in the URL. The complexity is that the site is not at the root of my localhost, so the problem was that a couple of folder levels were missing between “localhost” and the “@”.

However, your option 2 is my preference anyway. I created a custom text.php file in my /snippets/blocks folder as follows and the links now work perfectly.

<?php /** @var \Kirby\Cms\Block $block */ ?>
<?= $block->text()->permalinksToUrls();

Thanks for your help as always.

I am running into the same issue with Kirby 4.1.0 when developing on localhost (MAMP). The permalinksToUrls() method fixes this, but seems a bit involved to add this to every writer and textarea rendered in every template.

I already tried changing my config.localhost.php to include the subdomain in my ‘url’

<?php

return [
    'url' => 'http://localhost:8888/subdomain'
];

But the permalinks still resolve to http://localhost/@/page/permalink instead of http://localhost/subdomain/@/page/permalink

1 Like