Just parse kirbytags


I needed to parse just kirbytags in a field witout all the markdown and smartypants stuff and I didn’t find a proper solution.

So for everyone who only needs to parse kirbytags in a field or string.
Put following lines of code into a plugin and you can then use the $field->kirbytags() method or use the helper function kirbytags($field).


 * Kirbytags parser
 * @param  Field/string $field
 * @return string
function kirbytags($field, $page = null) {
  return (string) new Kirbytags($field, $page);

 * Kirbytags parser
 * @param  Field $field
 * @return Field
$kirby->set('field::method', 'kirbytags', function($field) {
  $field->value = kirbytags($field);
  return $field;

class Kirbytags extends Kirbytext {

  public function parse() {

    if(!$this->field) return '';

    return preg_replace_callback('!(?=[^\]])\([a-z0-9_-]+:.*?\)!is', array($this, 'tag'), $this->field->value);




I recently reported a bug that I found with Kirbytext tags:

I’ve also started looking at alternative solutions and I have found at least one:


@jenstornell I think you have to have self-contained divs, then you wouldn’t run into this problem (i.e. not start with a closing div and end with an opening div)


I agree. It seems to have something to do with it. I’ve added some more info about why it can make sense to start with a closing tag https://github.com/getkirby/kirby/issues/628.

I also put the question; Why does it care about what my HTML looks like?