view doesn't show up

I want to modify the content that shows up on my Magento website's product view page and I want to create my own custom block for use on the page as well.

What I've Done

Create Layout Updates For Product View Handle

To update what was displayed on the product's view page, I put the following layout updates within my local.xml file:

<catalog_product_view>
    <reference name="root">
        <action method="setTemplate"><template>page/1column.phtml</template></action>
    </reference>
    <reference name="content">
        <remove name="product.tierprices" />
        <remove name="product.info.upsell" />
        <remove name="product.clone_prices" />
        <remove name="product.description" />
        <remove name="product.tag.list" />
        <remove name="product.info.addto" />
        <remove name="product.info.addtocart" />
        <remove name="product.info.downloadcontent" />
        <remove name="product.info.extrahint" />
        <remove name="product.info.options.wrapper.bottom" />
        <remove name="product.info.container1" />
        <remove name="product.info.container2" />
        <remove name="alert.urls" />
        <remove name="catalog.compare.sidebar" />
        <remove name="cart_sidebar" />
        <remove name="right.permanent.callout" />
        <remove name="paypal.partner.right.logo" />
        <remove name="right.poll" />
        <remove name="bundle.tierprices" />
        <remove name="product.attributes" />

        <!-- This should override the original product.info block -->
        <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
            <!-- Custom MyNamespace_Videos_Block_Player block -->
            <block type="videos/player" name="videoPlayer" as="videoPlayer" template="video/player.phtml"/>
        </block>

    </reference>
</catalog_product_view>

At this point, I confirmed the remove nodes worked. Obviously, because I hadn't created the videos/player block class at this point, nothing showed up.

Custom Module

I created a custom module by creating the following folder structure under app/code/local :

  • MyNameSpace
  • MyNameSpace/Videos
  • MyNameSpace/Videos/Block
  • MyNameSpace/Videos/etc
  • I created the config file for the module at MyNameSpace/Videos/etc/config.xml and placed the following xml nodes within:

    <?xml version="1.0"?>
    <config>
        <modules>
            <mynamespace_videos>
                <version>0.0.1</version>
            </mynamespace_videos>
        </modules>
        <global>
            <blocks>
                <videos>
                    <class>MyNamespace_Videos_Block</class>
                </videos>
            </blocks>
        </global>
    </config>
    

    I then enabled the module and verified that it worked.

    Custom Block Class

    I've created a custom block within MyNameSpace/Videos/Block/Player.phtml with the following:

    class MyNamespace_Videos_Block_Player extends Mage_Core_Block_Template {
        public function _toHtml() {
            echo "Block's _toHtml() method called!";
            parent::_toHtml();
        }
    }
    

    Custom Template File

    I then created the custom template file at design/frontend/mythemepackage/default/template/video/player.phtml that contains the following:

    <!--Check to see if Magento sees this!-->
    <?php Mage::log(get_class($this)); ?>
    

    Modified catalog/product/view.phtml

    To have my videos/player block show up within catalog/product/view.phtml , I copied app/design/frontend/base/default/template/catalog/product/view.phtml to my design package at app/design/frontend/mythemepackage/default/template/catalog/product/view.phtml .

    I then added the following line to the newly copied view template:

    <b>This text will show up!</b>
    <i>The following wont: </i>
    <?php echo $this->getChildHtml('videoPlayer'); ?>
    

    Outcome

    With the above configuration, I cannot get the videoPlayer block to render.

    Here's what I know:

  • I can see the normal html text in my catalog/product/view.phtml file. I cannot see what is echoed from $this->getChildHtml('videoPlayer');
  • The _toHtml() method of MyNamespace_Videos_Block_Player class is not being called and I cannot see any output from my video/player.phtml template.
  • If I copy catalog.xml from app/design/frontend/base/default/layout/catalog.xml to app/design/frontend/mythemepackage/default/layout/catalog.xml and then add my videos/player block to it, I can see "Block's _toHtml() method called!" that has been echoed by the videos/player block. The following is what the addition to catalog.xml looks like:
  •     <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
            <block type="videos/player" name="videoPlayer" as="videoPlayer" template="video/player.phtml"/>
        </block>
    
  • Even though using a local version of catalog.xml calls my block's _toHtml() method, nothing is output from my template.
  • Questions

    I've spent quite a while doing troubleshooting for this. I've deleted the cache completely at var/cache and verified that the module is active and is working.

  • What am I missing? What needs to happen to get the block to render?
  • Why does copying catalog.xml and adding my block there work but updating through local.xml doesn't?

  • Hello I think you can add <catalog_product_view> tag in your module layout xml

    <catalog_product_view>
         <reference name="content">
             <reference name="product.info">
                 <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
                     <block type="videos/player" name="videoPlayer" as="videoPlayer" template="video/player.phtml"/>
                 </block> 
             </reference>
        </reference>
    </catalog_product_view> 
    

    This will be help you

    链接地址: http://www.djcxy.com/p/59478.html

    上一篇: 最好的方式来处理块的形式?

    下一篇: 视图不显示