Access component properties from a page or partial
4
There are multiple ways to access a component's properties. Given this is our component:
class Example extends Component
{
// Note the property is public!
public $foo = 'bar';
public function onRun()
{
// This creates a varaible `foo` in twig.
$this->page['foo'] = $this->foo;
}
}
You can acceess it's properties like this:
[example]
==
function onStart()
{
// Access it in the code section via the components
// array on the page property.
$valueOfFoo = $this->page->components['example']->foo;
}
==
Since the property's visibility is public you
can access it using {{ example.foo }}. Private
properties won't be accessible this way.
Because we also set the property on the `page`
variable in `onRun` it is also accessible
directly via {{ foo }}.
There are no comments yet
Be the first one to comment