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)
.
<?php
/**
* 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);
}
}