Define a global variable on the CMS controller
3
To define a variable that is available on your controller everywhere, you can use the following event listener:
\Event::listen('cms.page.init', function($controller) {
$controller->vars['my_special_variable'] = 'some-value';
});
You can now access this variable in Twig or any PHP code section that has access to the CMS controller instance:
{{ my_special_variable }}
Page lifecycle example, works in Components as well:
function onStart()
{
$special = $this->controller->vars['my_special_variable'];
}
There are no comments yet
Be the first one to comment