Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing data from layout to block controller using setData
    text
    copied!<p>I'm trying to set a variable in my local.xml file for my custom block:</p> <pre><code>&lt;layout&gt; &lt;!-- ... --&gt; &lt;page_homepage&gt; &lt;!-- ... --&gt; &lt;reference name="root"&gt; &lt;!-- ... --&gt; &lt;block type="core/template" name="home_page_sections" template="page/homepage/sections.phtml"&gt; &lt;block type="layout/carousel" name="featured_carousel"&gt; &lt;action method="setData"&gt; &lt;name&gt;filter_attribute&lt;/name&gt; &lt;value&gt;is_featured_product&lt;/value&gt; &lt;/action&gt; &lt;/block&gt; &lt;/block&gt; &lt;/reference&gt; &lt;/page_homepage&gt; &lt;/layout&gt; </code></pre> <p>But I am not getting the data on the other end in my controller:</p> <pre><code>class Foo_Layout_Block_Carousel extends Mage_Core_Block_Template { public function __construct() { parent::__construct(); $filterAttribute = $this-&gt;getFilterAttribute(); // Nothing $filterAttribute = $this-&gt;getData('filter_attribute'); // Nada // Alright, fine, what DO I have?! var_dump($this-&gt;getData()); // array(0) {} ... Argh! } } </code></pre> <p>From all my searching I've found that this really should work, but since it does not, I have a feeling I'm missing something obvious. Here is my layout module's configuration (I'm using a single module to define a homepage and any other blocks I need for the site):</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;config&gt; &lt;modules&gt; &lt;Foo_Layout&gt; &lt;version&gt;0.1.0&lt;/version&gt; &lt;/Foo_Layout&gt; &lt;/modules&gt; &lt;global&gt; &lt;page&gt; &lt;layouts&gt; &lt;foo_homepage translate="label"&gt; &lt;label&gt;Homepage&lt;/label&gt; &lt;template&gt;page/homepage.phtml&lt;/template&gt; &lt;layout_handle&gt;page_homepage&lt;/layout_handle&gt; &lt;/foo_homepage&gt; &lt;/layouts&gt; &lt;/page&gt; &lt;blocks&gt; &lt;layout&gt; &lt;class&gt;Foo_Layout_Block&lt;/class&gt; &lt;/layout&gt; &lt;/blocks&gt; &lt;/global&gt; &lt;/config&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload