Referencing a Field within Another Field

Is there a way to reference blueprint field data in say a textarea? For example, I have a blueprint with a text field and I want to be able to reference that text field in my markdown, something like using handlebars.

Today's deal is {{text.data}} thank you for visiting.

Where text.data is a field in the blueprint.

Do you really mean in the blueprint? The blueprint doesn’t store data.

I guess it would be the content then, not the blueprint.

You can achieve this with a kirbytext hook that replaces your text within the braces. See example here: https://getkirby.com/docs/cookbook/forms/email-with-attachments#the-success-page.

Instead of the session data, you would replace with content from the field. With $data['parent'] you have access to the current page object.

I’m probably not seeing what you are referring to in that link but this is what I’m hoping to accomplish.

Yes, I know. Within the kirbytext hook, you would replace {{ intro }} with $data['parent']->intro(). Note that this won’t happen in the Panel, but on the frontend when you call $page->text()->kt().

<?php

Kirby::plugin('your/plugin', [
    'hooks' => [
        'kirbytags:after' => function ($text, $data, $options) {
    
            return Str::template($text, [
                'intro'   => $data['parent']->intro(),
            ]);
        }
    ],
]);
2 Likes

you could even use all fields like when prefixing {{ page.VARNAME}}

<?php

Kirby::plugin('your/plugin', [
    'hooks' => [
        'kirbytags:after' => function ($text, $data, $options) {
    
            return Str::template($text, [
                'page'   => $data['parent']
            ]);
        }
    ],
]);

Great idea! (But could lead to undesired results depending on what is stored in the fields).

Thanks! Works great!