This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I'm getting a cookie value in (the code section of) my "head" partial. I need to use this value in the body of all my layouts and in the footer partial. What is the best way to retrieve a cookie value in the head partial and make this value available to the layout and other partials?
yes, that seems to be the direction October pushes towards, but it would be sweet to do it once in the "head" partial, rather than in six layouts. Is there any way to do it this way?
bmcwilliams said: yes, that seems to be the direction October pushes towards, but it would be sweet to do it once in the "head" partial, rather than in six layouts. Is there any way to do it this way?
You can do it by handling CMS (frontend) events in your plugin and setting global Twig (page) variable, check listed events here: https://octobercms.com/docs/api/cms/page/beforedisplay
I'm not using a plugin. I just want to grab the cookie value in the code section of my "head" partial and make that value available to all layouts that include the "head" partial and other partials.
You can do this using the viewBag component... in your partial, set a viewBag property with the cookie value:
==
function onStart()
{
$this->viewBag->setProperty('myVar', 'My Value');
}
==
... partial markup
Then use the value within your other partials / layout markup:
{{ viewBag.myVar }}
Hope that helps.
i think this is close, but this code snippet generates the error: "Call to a member function setProperty() on array"
== function onStart() { $this->viewBag->setProperty('myVar', 'My Value'); }
... partial markup
Last updated
1-9 of 9