I want a kirbytag that I can use like this:
(block: my-items content: my-field)
Which, when used in a textarea, for example, will replace the tag with content from the my-items
snippet and will pass the value of this pageās my-field
field to it. Iāve made it like this:
Kirby::plugin('oblik/ikarov', [
'tags' => [
'block' => [
'attr' => [
'content'
],
'html' => function ($tag) {
$markup = snippet(
'blocks/' . $tag->value,
[
'field' => page()->{$tag->content}()
],
true
);
return $markup;
}
]
]
]);
This correctly calls the snippet and passes the field value to it. However, in the snippet, I use whitespace to structure the code. When itās later output in the template, the Markdown parser puts <pre>
tags because it thinks the markup is a code block (due to the whitespace).
Instead of using $field->kirbytext()
to output the textarea content, I tried with $field->markdown()->kirbytags()
. This solved the problem with the <pre>
tags, but now there were mystery <p>
tags all over the place.
My next solution was to simply remove the whitespace in the tag function before returning the markup:
return preg_replace('/\s+/', ' ', $markup);
This appears to work perfectly, but I still feel like itās a bad solution open to issues. Is there a better way to handle this problem?
I donāt know how kirbytext()
works internally, but perhaps the whole kirbytag parsing should be part of the custom Markdown parser? I mean, it should process the tags and then do no more alterations to whatever they turned into, without conflicting with other Markdown rules.