How to Stop a Custom Block from Auto Rendering in Magento

blockslayouttemplate

I have a custom block and when I add it to local.xml it auto renders:

<catalog_product_view>
    <reference name="head">
        <action method="addJs">
            <script>fileuploader/filepop.js</script>
        </action>
    </reference>
    <reference name="content">                 
        <block type="fileuploader/fileuploader" name="product.attachments" template="fileuploader/desc_attachments.phtml"/>
    </reference>
</catalog_product_view>

This is bad because I actually want it in a very specific spot. I am able to call this block using getBlockHtml in my catalog/product/view.php but then it shows up twice.

How can I get the block to STOP auto rendering?? Below is the code for the block:

class Uni_Fileuploader_Block_Fileuploader extends Mage_Core_Block_Template {

    public function _prepareLayout() {
        return parent::_prepareLayout();
    }

    public function getProductAttachments($productId=0) {
        $attach = array();
        $_helper = Mage::helper('fileuploader');
        $data = Mage::getModel('fileuploader/fileuploader')->getFilesByProductId($productId);
        $totalFiles = $data['totalRecords'];
        if ($totalFiles > 0) {
            $record = $data['items'];
            $i=0;
            foreach ($record as $rec) {
                $i++;
                $file = $_helper->getFilesHtml($rec['uploaded_file'], $rec['title'],$i,true,$rec['content_disp'],true);
                $attach[] = array('title' => $rec['title'], 'file' => $file, 'content' => $rec['file_content']);
            }
        }
        return $attach;
    }

}

Best Answer

It's because you added it under the content block. Replace this:

<reference name="content">                 
    <block type="fileuploader/fileuploader" name="product.attachments" template="fileuploader/desc_attachments.phtml"/>
</reference>

with this:

<reference name="product.info">                 
    <block type="fileuploader/fileuploader" name="product.attachments" template="fileuploader/desc_attachments.phtml"/>
</reference>

Now you can place it wherever you want using getBlockHtml.

Please tell me how it went after that.

Related Topic