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;
 }
}
asked Jun 17, 2015 at 22:04

1 Answer 1

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.

answered Jun 18, 2015 at 1:25
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. Commented Jun 18, 2015 at 14:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.