Escape Kirbytag Parenthesis

Hey,
I am pretty sure about this topic was spoken before but I could only find threads about escaping parenthesis inside kirbytags. But I want the whole kirbytag to be escaped inside a <code> element and I just don’t get it to work…

Just like: (link:http://google.com text:Google)

Dennis

1 Like

The getkirby.com website does it like this:

(\link: http://wikipedia.org)

(https://github.com/getkirby/getkirby.com/blob/master/content/1-docs/3-content/2-text/docs.txt)

And then a str_replace in the template:

<?php echo str_replace('(\\', '(', kirbytext($page->text())) ?>

(https://github.com/getkirby/getkirby.com/blob/master/site/templates/docs.php)

2 Likes

Nice, that does the trick :wink:

But why doesn’t this work in a kirbytext post-filter? If I use the code below it just removes the kirbytag completely from the DOM.

kirbytext::$post[] = function($kirbytext, $value) {
    return str_replace('(\\','(', $value);
};

Good question, I would have expected a filter to work as well. Will get back to this later (after cooking and eating :shallow_pan_of_food:).

1 Like

Hm, I tested this and the filter works for me as expected (tested with Kirby 2.5.4) :thinking:

I realized that it just doesn’t work within the columns-plugin by @bastianallgeier (columns.php). But I am definitely not enough of a regex-wizard to figure out why :rofl:

I assume this is not because of the regex pattern but rather because the kirbytext() method is called on the field within the pre filter (so that the post filter does not have any effect).

Sounds reasonable. I think I’ll stay with your original answer as it works seamlessly.