This may sound quite basic, but I haven’t found the solution after looking around for a while and testing several options.
I need to pass a dynamic variable to a page, with a value that’s coming from an API, something like this:
public static function getNumber() {
$number = '123'; // Code to obtain number
return $number;
}
But not sure if this actually works as I haven’t found a way to pass this to the page content. I’d like this number to appear within the copy, so it has to be passed as a variable to the page content.
Hi, Thanks for your answer, I will check on the links. But please not that I need to pass this variable to the page content (.md file), not to the template, so I can add it to the front matter of the page and then in the content like “…lorem ipsum dolor {{ page.header.number }} sit met consectetur…”
I’ve managed to make my theme generate a variable which is accessible in the templates with $this->grav['twig']->twig_vars['variable'] = $data; and using it like {{ variable }} but I have not been able to pass this to the page content.