October CMS Component Load on Layout
Im new to October CMS I read the documentation and its states that components can be used inside a layout on the PHP Section (https://octobercms.com/docs/cms/layouts)
i want to create a component that will be used as configuration file for my theme, declaring global variables, that will be used on all pages, but will also be used for all layouts i will create. but i cant find how to do it via code. Like include a file. i want this to used this parameters inside the PHP Section of the layout and the pages.
If components is not the best way, can you ppl sugest me what is the best way
Answer
I did before search a lot to find some way that I can share variables to all my layouts and pages but couldn't find anything.
So I tried my own trick and it worked.
In your frontend you must have header.htm
partial. so in the code section in it write a onStart()
function and set your global variables so you can access them from any layout or page which includes the header
partial.
For example in your header.htm
code section:
function onStart() {
$this['my_var'] = ['name' => 'Ahmed', 'age' => 17];
}
That way you can access my_var
variable wherever you want in all your layouts and pages which header.htm
partial is included.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?