Pregunta

is this possible? I need to dynamically assign a variable used in a templates Model class. This variable will be generated via a CMS page. Below is the template and block in question. How can I pass a dynamically assigned variable to it's model?

<reference name="content">
        <block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml" ></block>
</reference>

If possible i'd like to assign a variable to this via the block and pass it to the model using session variables (if I cant access this variable from the block outright).

This is the location of the block i'd like to access this variable:

code/core/Mage/Catalog/Block/Layer/View.php

Of course, I will extend this later as it is core atm.

¿Fue útil?

Solución

You can always set a variable on a block like that:

<reference name="content">
    <block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml">
        <action method="setMyVar">
            <value>myvalue</value>
        </action>
    </block>
</reference>

This will set the variable my_var with the value myvalue in the specified block. You will be able to get the value of this variable via $this->getMyVar(). Note that this will only work after the loadLayout() method of the respective Mage_Core_Controller_Front_Action has been called.

Otros consejos

I know this is an old thread but came across it and noticed that the correct way to pass a variable to a method should be with an argument tag:

   <reference name="content">
        <block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml">
            <action method="setMyVar">
                <argument name="value" xsi:type="string">myvalue</argument>
            </action>
        </block>
    </reference>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top