Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Reference block defined in CMS content from CMS layout update? 
 
Yireo
Member
 
Avatar
Total Posts:  52
Joined:  2008-05-26
The Netherland
 

Hi,

I am just playing around with the following: On the CMS page “Home page” I have added the following {{block}} to the Content-area. This adds a product with ID 17 to the page.

{{block type="catalog/product_view" name="product.info" product_id="17" template="catalog/product/view.phtml"}}

But this only contains the block itself, not the child-blocks like “description” or “media”. So next, I want to make a reference to add the child-blocks to the page - by adding the following code to the Layout Update XML configuration of the same CMS page “Home page”:

<reference name="content">
<
block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
</
reference>

This works - so far, so good. But what I need is to put the “product.info.media” block inside the “product.info” block:

<reference name="product.info">
<
block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
</
reference>

This doesn’t work. My question is: Does the architecture allow the “Layout Update XML” of a CMS-page to alter the XML-structure including the “Content” of the same CMS-page? Or are both parts integrated at the same time into the XML-configuration, so they can not reference each other? I think the latter is true, but it would be much cooler if the first is true.

Note: Adding the {{block}}-code to the Content-area, instead of adding it to the Layout Update XML (which would make it all a piece-of-cake), is a forced decision, explained in the following threads:
http://www.magentocommerce.com/boards/viewthread/19173/
http://www.magentocommerce.com/boards/viewthread/29039/

Regards,
Jisse Reitsma

 
Magento Community Magento Community
Magento Community
Magento Community
 
kiatng
Enthusiast
 
Total Posts:  875
Joined:  2008-09-03
Kuala Lumpur, Malaysia
 

Hi

Can you share if you have figured out the way to add a child block?  I’m trying to add a child within the media block in a custom module without changing the catalog.xml and the view.phtml:

<cpigs_upload>
     <
block type="cpigs/upload" name="cpigs.upload" as="cpigs_upload" template="cpigs/upload.phtml"/>  
</
cpigs_upload>
<
reference name="product.info.media">
     <
action method="setChild"><child>cpigs_upload</child><block>cpigs_upload</block></action
</
reference>

The idea is to get the custom block to render when this is executed:

<div class="product-img-box">
     
<?php echo $this->getChildHtml('media'?>
</div>

in view.phtml. Anyone knows if this is possible?

[SOLVED]
In the custom layout cpigs.xml:

<catalog_product_view>
    <
reference name="product.info.media">
          <
block type="cpigs/upload" name="cpigs.upload" as="cpigs_upload" template="cpigs/upload.phtml"/>
          <
block type="catalog/product_view_media" as="cpigs_media" template="catalog/product/view/media.phtml"/>  
          <
action method="setTemplate"><template>cpigs/cpigs.phtml</template></action>  
    </
reference>    
</
catalog_product_view>
which declares 2 child blocks within the “as=media” block and the action method to override the default template.

And then in cpigs.phtml:

<?php
    
echo $this->getChildHtml('cpigs_media');
    echo 
$this->getChildHtml('cpigs_upload');
?>
which renders the “as=media” (redeclared “as=cpigs_media” in the layout xml) block first and then the custom block.  With this method, there is no modification on the other template and layout files.

Sorry to have hijacked the original post, but I think it is possible to create child blocks in the CMS layout and update the entire layout content with similar codes like my custom layout.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top