How do I output internal page links (UUIDs)?

I use the new “link to pages” function in a writer field. How do I output these internal page links?

<?= $page->text() ?> works fine for text formatting, but links are output as UUIDs:
https://localhost:8880/@/page/gIRJQztFbfi6VenB

I cannot find any instructions on this in the v4 documentation.

All PHP methods and helpers of Kirby support the query for UUIDs. This includes: Helper functions like page() […] Kirby will do the search for you. It will also automatically recognize whether you pass a file path or a UUID (each UUID starts with a URI protocol like page://).
(Source: Unique IDs & Permalinks | Kirby CMS)

:arrow_up: Shouldn’t this also work with <?= $page->text() ?>

I already use UUIDs elsewhere (related links), but they are not integrated in a writer field.

I must say that I don’t understand your question.

This is the link to the page, in the form of the permalink. To make sure the link is correct even if you later change the slug of the page.

i think the intention is to resolve the permalink to the page url and how to do so when calling ->kirbytext()/html() on a field.

1 Like

Ah, ok, there is a field method called $field->permalinksToUrls().

I would like to explain my question in more detail.

I have created an internal page link in a writer-field.

The writer-field is rendered with <?= $page->text() ?>.
This also works well, as all text formatting is rendered.
But the link is only displayed as a UUID permalink:

However, “/datenschutz” should be displayed there.

$field->permalinksToUrls() only outputs the link, not the writer content.

In the instructions, I understand that the permalink is automatically converted into a “readable” link. Or does the output have to be extended with an if query?
I hope that my little question is now easier to understand. :wink:

Works fine for me

$page->text():

Aenean eu leo quam. <a href="/@/page/ZWZVZSlNpA6VJzXZ">Pellentesque</a> ornare sem lacinia quam venenatis vestibulum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum id ligula porta felis euismod semper. Donec sed odio dui. Etiam porta sem malesuada magna mollis euismod.

$page->text()->permalinksToUrls() :

Aenean eu leo quam. <a href="http://k4rc.test/notes">Pellentesque</a> ornare sem lacinia quam venenatis vestibulum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum id ligula porta felis euismod semper. Donec sed odio dui. Etiam porta sem malesuada magna mollis euismod.
2 Likes

Thank you @texnixe , you’ve saved my monday :+1:

$page->text()->permalinksToUrls() works for me now too.

I have no idea what I did wrong on the first try…
Perhaps I was not familiar with the “copy-and-paste” function :sweat_smile:

Where can I find detailed information about permalinksToUrls?
No result is displayed in the guide. And not here in the forum either.

Nowhere atm (unless you clone our getkirby.com repo), the complete docs will be online at release time.

1 Like

I’ve been working with Kirby for a few months now and have learned and achieved a lot thanks to your great help and the super support here in the forum :star2:

But now I’m stuck in the same place and can’t get any further. It’s probably just a small problem and my :brain: mental block is unnecessarily large.

How do I output a permalink that I have created in a layout or block?

$page->layout()->toBlocks()

In the individual block snippets where needed. For a text block, in the text block snippet, etc.

1 Like

That was too easy. I couldn’t see the wood for the trees. I already had a text.php snippet and only had to add ->permalinksToUrls() to make it work. Thanks for showing me the right way.

<?php /** @var \Kirby\Cms\Block $block */ ?>

<?php 
$text           = $data->text()->permalinksToUrls(); // <--- Here it is
$textGroesse  	= $data->textGroesse()->isNotEmpty() ? $data->textGroesse() : null;
$textWrapping   = $data->textWrapping()->isNotEmpty() ? $data->textWrapping() : null;

if ($textGroesse || $textWrapping) {
    $class = $textGroesse . $textWrapping;

    $tags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol'];

    foreach ($tags as $tag) {
        $text = preg_replace("/<$tag>/", "<$tag class=\"$class\">", $text);
    }
}

echo $text;