I have an element called userbar on every page – it tells the user if he/she is logged in or not. I created this element and echoed it in default.ctp:
<?php echo $this->element('userbar', array('text' => 'You are not logged in.')); ?>
Now it shows on every page. However, I can’t find anywhere how to change this text. For e.g., I would like to access this element from some controller and change it. How?
You set a view variable and then use that.
And then in the view:
Considering this is something you’d do on every page request its best to put it in the
AppController::beforeFilter().There are other ways to do this. But if you render the element in the controller you still need to set a view variable and echo that in the view.
Hope this helps.