Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Cache problem with blog list page

Started by Muut Archive 10 years ago · 1 replies · 345 views
10 years ago

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.

10 years ago

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: https://github.com/getgrav/grav-plugin-shortcode-core for the Core plugin, specifically the shorcodes/ folder.

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

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2959 9 years ago
Archive · by Muut Archive, 9 years ago
3 1123 9 years ago