I want to know how to use layout.xml with event observer.
I want to show a message in footer when payment made successfully.
I know I have to use the event checkout_onepage_controller_success_action
How to use controller or layout.xml with event observer?
Best Answer
The event
checkout_onepage_controller_success_action
is triggered right before the layout is rendered, so you can still manipulate it.The observer only receives the order id as a parameter, so you have to get the layout via app model:
Now you can do your changes programmatically, like this:
If you use the
controller_action_layout_load_before
event, you can also load a custom layout handle like this, if on the success page:which you can define in XML:
Update: The footer block is cached, so we have to make sure that a different version is fetched from the cache if the message is present. For example:
Reference your block by name and use
setData()
. For example:And in the template: