Looking at the columns example from the Cookbook, it uses preg_replace_callback, i.e. executing the code manipulation – and calling kirbytext() – only for instances where the regex matches, while your code applies the manipulation to any content piped into kirbytext(). That’s where I’d suspect the eternal loop to stem from.
That’s a really good point. Sorry, I’m not very experienced with PHP, but any ideas how I could avoid that whilst also making sure that I’m manipulating the whole content piped into kirbytext()? I had a few passes at using preg_replace_callback with a regex expression matching everything, but had the same issue (predictably, I suppose).
only applies the cutting-into-columns routine on text wrapped between (columns) and (/columns) in the text. You’ll need some kind of check/filter to ensure that the calls to kirbytext() from within your function don’t trigger the same loop again.
The easiest would be to stick to the cookbook example where the text-to-be-divided is wrapped within such Kirbytags. Alternatively, you could try by introducing a filter to only do the “magic” after the regex actually split anything:
Sebastian, thank you so much for your help here. That has solved the problem and really clarifies the root cause of it. I had a vague inkling about dealing with situations where this function would operate on content without this new separator, although I’m not sure I would have gotten there myself. Thank you.