Sorry, misread your question…
The only solution I can think of is adding an
onPageContentRaw event to your theme or plugin and replace a placeholder for the variable in the content of the page.
If your page contains “Our monthly special is [discount] off” the function could look like:
public function onPageContentRaw(Event $e)
// Get a variable from site.yaml
$discount = $this->grav['config']->get('site.my_discount');
// Get the current raw content
$content = $e['page']->getRawContent();
// Replace placeholder [discount] inside content of page
$content = preg_replace('/\[discount\]/', $discount, $content);
// Set the new content for the page
onPageContentRaw will only be fired once when the page is processed for the first time. Once the page is cached it will not run. When you update site.yaml, the cash will be marked dirty and
onPageContentRaw will run again.
Note, for efficiency reasons, I would build in a check to prevent the function to be called on all pages…