【问题标题】:Using getChildHtml to display product attributes not working使用 getChildHtml 显示产品属性不起作用
【发布时间】:2014-04-11 13:31:27
【问题描述】:

我在我的 catalog.xml 文件中添加了一个,创建了一个 specification.phtml 文件用作模板,我正在调用 echo $this->getChildHtml('specifications');在我的 view.phtml 文件中。

但是它根本没有显示任何东西。我基本上已经在产品描述的相同类型的事物之后镜像了所有内容(有效),但我没有任何运气。

我试图拉入的内容位于产品页面下,我认为是一个标有“规格选项卡”的自定义部分。不确定字段名称中的空格是否导致问题或什么。

这是我的 view.phtml 文件中的内容:

<div id="product-tabs" class="tabs">

    <ul class="tabs-nav">
        <li><a href="#tab-description"><?php echo $this->__('Description'); ?></a></li>

        <?php
        $specificationsTabContent = $_product->getSpecificationsTab(); 
        $videoTabContent = $_product->getVideoTab();
        $faqTabContent = $_product->getFaqTab();
        $howitworksTabContent = $_product->getHowitworksTab();
        $awardsTabContent = $_product->getAwardsTab();

        ?>

        <?php #if ($this->getChildHtml('specifications_tab')): #($this->getChildHtml('product_attributes')): ?>
        <?php if (!empty($specificationsTabContent)) : ?>
        <li><a href="#tab-details"><?php echo $this->__('Specs'); ?></a></li>
        <?php endif; ?>

        <?php if (!empty($videoTabContent)) : ?>
        <li><a href="#tab-video"><?php echo $this->__('Videos14'); ?></a></li>
        <?php endif; ?>

        <?php if (!empty($faqTabContent)) : ?>
        <li><a href="#tab-faq"><?php echo $this->__('FAQs'); ?></a></li>
        <?php endif; ?>

        <?php if (!empty($howitworksTabContent)) : ?>
        <li><a href="#tab-howitworks"><?php echo $this->__('How It Works'); ?></a></li>
        <?php endif; ?>

        <?php if (!empty($awardsTabContent)) : ?>
        <li><a href="#tab-awards"><?php echo $this->__('Awards'); ?></a></li>
        <?php endif; ?>

        <!-- <li><a href="#tab-tags"><?php #echo $this->__('Tags'); ?></a></li> -->

        <?php if ($this->getChildHtml('snippet_product_view_tab_1')): ?>
            <li><a href="#tab-custom-1"><?php echo $this->__('Custom 1'); ?></a></li>
        <?php endif; ?>

        <?php if ($this->getChildHtml('snippet_product_view_tab_2')): ?>
            <li><a href="#tab-custom-2"><?php echo $this->__('Custom 2'); ?></a></li>
        <?php endif; ?>
    </ul>

    <div class="tabs-content">

        <div id="tab-description">
            <?php echo $this->getChildHtml('description'); ?>
        </div>

        <div id="tab-details">
            <?php #echo $this->getChildHtml('specifications'); ?>
            <?php echo $specificationsTabContent; ?>
        </div>

        <div id="tab-faq">
            <?php echo $faqTabContent; ?>
        </div>

        <div id="tab-video">
            <?php echo $videoTabContent; ?>
        </div>

        <div id="tab-howitworks">
            <?php echo $howitworksTabContent; ?>
        </div>

        <div id="tab-awards">
            <?php echo $awardsTabContent; ?>
        </div>

        <!-- <div id="tab-tags">
            <?php echo $this->getChildHtml('product_additional_data') ?>
        </div> -->

        <?php if ( $this->getChildHtml('snippet_product_view_tab_1') ): ?>
        <div id="tab-custom-1">
            <div class="snippet snippet-product-view-tab-1"><?php echo $this->getChildHtml('snippet_product_view_tab_1') ?></div>
        </div>
        <?php endif; ?>

        <?php if ( $this->getChildHtml('snippet_product_view_tab_2') ): ?>
        <div id="tab-custom-2">
            <div class="snippet snippet-product-view-tab-2"><?php echo $this->getChildHtml('snippet_product_view_tab_2') ?></div>
        </div>
        <?php endif; ?>
    </div>

  </div>

这是我添加到我的 catalog.xml 中的 XML:

            <!-- specifications -->
            <block type="catalog/product_view_specifications" name="product.specifications.tab" as="specifications" template="catalog/product/view/specifications.phtml"/>

这是模板文件specifications.phtml:

<?php $_specifications = $this->getProduct()->getSpecificationsTab(); ?>

<?php if ($_specifications): ?>
    <h2><?php echo $this->__('Specifications') ?></h2>

    <div class="long-description std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_specifications, 'specifications') ?>
    </div>
<?php endif; ?>

任何帮助将不胜感激!我对 Magento 或 PHP 不太熟悉。

谢谢,

【问题讨论】:

    标签: php xml magento


    【解决方案1】:

    只是改变
    &lt;?php #echo $this-&gt;getChildHtml('specifications'); ?&gt;

     <?php echo $this->getChildHtml('specifications'); ?>
    

    【讨论】:

    • 感谢您的回复,但这不是原因。我已将其注释掉以使内容显示未格式化。即使我删除 # 符号,它也不会显示任何内容。
    猜你喜欢
    • 1970-01-01
    • 2021-01-17
    • 1970-01-01
    • 2015-08-29
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    相关资源
    最近更新 更多