I need to use the same custom made block 2 times on the same page but with different values loaded from the database.
So I need to transfer a config value(Here called SimpleMenuInstanceRef) from my page.xml file to the block/model so each block knows what data to load from the database.
I am doing it with this block:
<block template="simplemenu/leftMenuTemplate.phtml" type="simplemenu/standard" name="leftMenu" as="leftMenu" translate="label">
<label>Left menu header</label>
<action method="setSimpleMenuInstanceRef"><SimpleMenuInstanceRef>4</SimpleMenuInstanceRef></action>
</block>
And this kinda works. In my leftMenuTemplate.phtml I can do a
echo $this->getSimpleMenuInstanceRef()
And this will show the value from the config.
But I need the value in my blocks _construct method so I can load data depending on its value. But doing a $this->getSimpleMenuInstanceRef in _construct don’t return anything. So how can I get the value in my block code, or do I need to transfer the value in an other way?
Edit: Changed __construct to _construct to match real code.
Yes, you need. Try to declare block as:
After doing this, you can easily access to the ‘instance’ var: