向我的phtml Magento 2主题添加属性

时间:2019-01-16 22:47:02

标签: attributes magento2.2

我正在使用Novetty主题,我想向文件添加一个块。我与主题提供者联系,他们告诉我将这行代码添加到 mytheme / CleverSoft_Base / templates / product / view / layouts / view_vertical_thumb.phtml

<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate('CleverSoft_Base::product/view/image_dimensions_chart.phtml')->toHtml(); ?>

我没问题,该阻止现在显示在我的产品页面上。一切都很好,但是我想将我创建的一些属性添加到块模板中, CleverSoft_Base :: product / view / image_dimensions_chart.phtml

我的代码是

<?php

$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();

/* image dimensions chart Attributes */
$a_dimensions_title = $_product->getAttributeText('a_dimensions');
$a_dimensions_value = $_product->getData('a_dimensions');

?>

<div class="image-dimensions-chart">

<h2>Image Dimensions Chart</h2>

<div class="row">
    <div class="col-md-3">Label:</div>
    <div class="col-md-3">Inches:</div>
    <div class="col-md-3">Inches(dec):</div>
    <div class="col-md-3">Millimeters:</div>
</div>
<div class="row">
    <div class="col-md-3">

        <?php if( $a_dimensions_title != '' ) { echo $a_dimensions_title; } else { echo '<span class="no-attribute-value">n/a</span>'; } ?>

    </div>
    <div class="col-md-3"> No Value </div>
    <div class="col-md-3">

        <?php if( $a_dimensions != '' ) { echo $a_dimensions; } else { echo '<span class="no-attribute-value">n/a</span>'; } ?>

    </div>
    <div class="col-md-3"></div>
</div>

<p>* fractions rounded to nearest 1/16"</p>

</div>

我被卡住的地方是我不确定如何在我的catalog_product_view.xml页面中引用它,因为它是view_vertical_thumb.phtml中的echo $ this-> getLayout()-> createBlock来显示另一个名为image_dimensions_chart的.phtml文件.phtml

在我的CleverSoft_Base :: product / view / image_dimensions_chart.phtml上使用echo $ this-> getLayout()-> createBlock时,我是否仍需要将其添加到catalog_product_view.xml或还有另一种添加属性的方法? >

是插入另一个phtml文件中的phtml。

0 个答案:

没有答案