0

So it's been a day and a half on this. Really need some help!

I cannot get $this->getChildHtml() to pull in my template. I have tried heaps but will outline the main things. First, my code:

app/design/frontend/.../template/pvtl/shiptwo/shiptwo-product-view.phtml

<p> This is the block you are looking for. </p> 

app/design/frontend/.../layout/pvtl_shiptwo.xml

<?xml version="1.0" ?> <layout> <catalog_product_view> <reference name="product.info"> <block type="pvtl_shiptwo/shiptwoView" name="view.shiptwo" as="shiptwoProductView" template="pvtl/shiptwo/shiptwo-product-view.phtml"/> </reference> </catalog_product_view> </layout> 

app/design/frontend/.../template/catalog/product/view.phtml

... <div class="product-view"> <div class="product-essential"> <?php echo $this->getBlockHtml('formkey') ?> <div class="no-display"> <input type="hidden" name="product" value="<?php echo $_product->getId() ?>"/> <input type="hidden" name="related_product" id="related-products-field" value=""/> </div> <div class="product-img-box"> <div class="product-name"> <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1> </div> <?php echo $this->getChildHtml('media') ?> </div> <div class="product-shop"> <form action="<?php echo $this->getSubmitUrl($_product, array('_secure' => $this->_isSecure())) ?>" method="post" id="product_addtocart_form"<?php if ($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>> <div class="product-name"> <span class="h1"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></span> </div> <!-- Below should print template contents but doesn't --> <div class="shiptwo_product_view"> <?php echo $this->getChildHtml('shiptwoProductView'); ?> </div> ... 

I know the block is being loaded as the name is printed when I use

<?php echo "<pre>", print_r($this->getSortedChildren(), 1), "</pre>"; ?> 

I also tried the following:

<?php echo "<pre>", print_r($this->getChild('shiptwoProductView')->getTemplate(), 1), "</pre>"; ?> 

This returns the correct template path. I have checked this path tens of times. It is correct.

To make sure the block was actually working I created a method inside Pvtl_Shiptwo_Block_ShiptwoView:

public function showText() { return 'Working!'; } 

and called

<?php echo "<pre>", print_r($this->getChild('shiptwoProductView')->showText(), 1), "</pre>"; ?> 

This returned the correct output.

I am completely stuck on this! Somebody please help!!

Edit By request, here is my config.xml

<?xml version="1.0" ?> <config> <modules> <Pvtl_Shiptwo> <version>0.1</version> </Pvtl_Shiptwo> </modules> <global> <blocks> <pvtl_shiptwo> <class>Pvtl_Shiptwo_Block</class> </pvtl_shiptwo> </blocks> </global> <frontend> <routers> <pvtl_shiptwo> <use>standard</use> <args> <module>Pvtl_Shiptwo</module> <frontName>Shiptwo</frontName> </args> </pvtl_shiptwo> </routers> <layout> <updates> <pvtl_shiptwo> <file>pvtl_shiptwo.xml</file> </pvtl_shiptwo> </updates> </layout> </frontend> </config> 

Edit

Screenshot of folder structure

2 Answers 2

1

make sure your custom block extends Mage_Core_Block_Template ?

Could show us your custom block file?

2
  • The block extends from Mage_Core_Block_Abstract. This is how I have worked it for all of my extensions previously. Should I be using _Template instead? Commented May 13, 2016 at 0:29
  • You can use Mage_Core_Block_Template . Anyway Mage_Core_Block_Template extends Mage_Core_Block_Abstract Commented May 13, 2016 at 19:33
0

I think the main problem is presented in your block naming part.

You should name your block file with first letter capital and then all others small like this:

class Pvtl_Shiptwo_Block_Shiptwoview 

Then in your layout file your code will be:

<layout> <catalog_product_view> <reference name="product.info"> <block type="pvtl_shiptwo/shiptwoview" name="view.shiptwo" as="shiptwoProductView" template="pvtl/shiptwo/shiptwo-product-view.phtml"/> </reference> </catalog_product_view> </layout> 
8
  • Thanks for the response but this made no difference. I think I'm going to go insane! Commented May 12, 2016 at 23:17
  • How is your config.xml? Please add to the qst. Commented May 12, 2016 at 23:18
  • I have added this to the question Commented May 12, 2016 at 23:25
  • Can you confirm your folder structure is like this: Pvtl->Shiptwo->Block->Shiptwoview.php and you have cleared your cache? Commented May 12, 2016 at 23:29
  • All that is correct. Will post screenshot Commented May 12, 2016 at 23:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.