2

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;
    }

}
5

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.

1
  • 1
    This is very close to the actual answer I came up with on my own. For those that are wondering why this is the case, its because the "content" block is a text/list type block. This block will auto render blocks added to it in the order they are added. – Bill Garrison Jun 18 '15 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.