Cache problem with blog list page

I have written a plugin which replaces some placeholders with generated content. Therefore it uses the “onPageContentProcessed” event and get the content by “getRawContent()” method.

This works fine on “normal” pages, but the plugin has no access to the content of the child pages listed in the blog list page.

I played around with the random plugin and dumped the variables “$taxonomy_map” and “$collection” which holds both a huge amount of data. But I nevertheless did get access to a childs content.

Is there an easier way to get the pages collection of a menu item instead of using the taxonomy object? If not, how can I access the content of theese child pages to replace them with dynamic generated content?

My main problem is, that all pages displayed on the blog list page, are cached immediately. So if the user clickes on an blog item to see the complete content, my plugin event do not fire, because the cache “thinks” this page is already cached.

It ‘should’ work without any issue because those two events are called whenever the page is not cached, and you call the ->content() method of the page in question. Your blog list page is probably calling ->summary() which in turn calls ->content(), so this is not an issue even for those subpages.

However, there is an easier solution. Why not create a shortcode-based plugin that does the replacement? Or, simply use Twig in your page content? There’s not much point writing a completely custom plugin to do this, when there simpler and thoroughly tested ways to do it.

Check out: for the Core plugin, specifically the shorcodes/ folder.

Here’s an unreleased plugin that extends shortcode-core and add it’s own custom shortcode.