'Hook' into `$block`'s writer field

Hey there,
I like the flexibility of writer fields, blocks & layouts very much - but one thing bothering me is that I cannot access writer field’s content via hooks like with kirbytext() - I want to programmatically change stuff, add some spice before outputting it, like altering all outgoing links automatically, etc …

How could that possibly be done?


You could use a field method that you call on every writer field when outputting it.

What about echoing the layout / blocks field? It’s all automatically done then, right?

That’s a different story. Then you would need a custom toBlocks()/toLayouts() method.

I’ll mark this a solution, although it seems quite a bit of work in order to “just” post-format some field content :slight_smile:

Well, for the kirbytext hooks to work, you call kirbytext() on a field. Internally, the kirbytext method triggers the hooks. The toBlocks() and toLayouts() method don’t do this. So I think, there is no other way to go about this.