I use custom shortcodes ( made with this method Custom Shortcodes > Simple Way ) to display informations coming from other pages.
My problem is that the pages with the shortcode do not update when the pages with the informations are edited. I’m wondering how to automate a cache clear.
To be a litte more explicit:
Say that I have some “source” pages with frontmatters like
--- title: Happy birthday to John date: 2020-02-17 news: thumbnail: gift.png targets: - page1 - page2 ---
and that a “target” page contains the shortcode
When this page is displayed, this shortcode is replaced by a list of
page.title, page.date, page.header.news.thumbnail for each source page where
header.news.targets contains the value
This is great, it works fine and it saves me the burden to frequently edit several target pages.
But when I modify a source page, the target pages are not updated until I manually clear the cache. Does anyone have some advices to improve my system ?
I never wrote a plugin. I think a simple solution may be to catch an appropriate grav event (onPageProcessed maybe ?), check if
page.header.news is defined, and clear the whole cache ( perhaps
grav[‘cache’]->clearCache( xxx ) ? ). What do you think ?
Or perhaps it would be better to catch the event, loop over all the pages, and clear the cache only for the ones that contains a matching shortcode ?