1

I added a image using Attribute

Store->attribute->product

and its text type and its name is

add_text_area

It's showing on the admin side and I can upload an image using WYSIWYG. And it's showing like this enter image description here

And I added on product page creating a new phtml file

Magneto_Catalog/templates/product/view/topattributes.phtml

<?php
$_product = $block->getProduct();
$_customAttribute = $_product->getResource()->getAttribute('add_text_area');
$_customAttributeValue = $_customAttribute->getFrontend()->getValue($_product);
?>
<p>Add Text Area: <?php echo $_customAttributeValue; ?></p>

And my xml call in catalog_product_view.xml file

<block class="Magento\Catalog\Block\Product\View\Attributes" template="Magento_Catalog::product/view/topattributes.phtml" name="product.info.topattribute" after="product.info.main"> 
</block> 

then I added it in catalog_product_view.xml file like this

<?xml version="1.0"?> 

<!-- 
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> 
--> 
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> 
<body> 

<referenceContainer name="content" > 
<block class="Magento\Catalog\Block\Product\View\Attributes" template="Magento_Catalog::product/view/topattributes.phtml" name="product.info.topattribute" after="product.info.main"> 
</block> 
<block class="Infortis\Base\Block\Product\View" name="product-view-wrapper" template="product/view.phtml" before="-"> </block> 
<container name="container_product_image_1" label="Product View, Image Column" /> 
<container name="container_product_primary_1" label="Product View, Primary Column, Container 1" /> 
<container name="container_product_primary_2" label="Product View, Primary Column, Container 2" /> 
<container name="container_product_secondary_1" label="Product View, Secondary Column, Container 1" /> 
<container name="container_product_secondary_2" label="Product View, Secondary Column, Container 2" /> 
<container name="container_product_lower_primary_1" label="Product View, Lower Primary Column, Container 1" /> 
<container name="container_product_lower_primary_2" label="Product View, Lower Primary Column, Container 2" /> 
<container name="container_product_lower_secondary_1" label="Product View, Lower Secondary Column, Container 1" /> 
<container name="container_product_lower_secondary_2" label="Product View, Lower Secondary Column, Container 2" /> 

<!-- Static blocks --> 
<block class="Magento\Cms\Block\Block" name="block_product_secondary_bottom"> 
<arguments> 
<argument name="block_id" xsi:type="string">block_product_secondary_bottom</argument> 
</arguments> 
</block> 




</referenceContainer> 

<!-- Reset attributes of main containers --> 
<referenceContainer name="product.info.main" htmlTag="" htmlClass="" before="-" /> 
<referenceContainer name="product.info.media" htmlTag="" htmlClass="" after="product.info.main" /> 

<!-- Insert product view blocks into the new product view wrapper --> 
<move element="product.info.main" destination="product-view-wrapper" /> 
<move element="product.info.media" destination="product-view-wrapper" /> 
<move element="bundle.options.container" destination="product-view-wrapper" /> 
<move element="product.info.details" destination="product-view-wrapper" /> 
<move element="catalog.product.related" destination="product-view-wrapper" /> 
<move element="product.info.upsell" destination="product-view-wrapper" /> 

<!-- Move some blocks to new positions --> 
<!-- <move element="product.info.stock.sku" destination="product.info.price" after="product.price.final" /> --> 
<!-- <move element="product.info.social" destination="product.info.main" after="-" /> --> 
<move element="product.info.overview" destination="product.info.main" before="product.info.price" /> 
<move element="container_product_primary_1" destination="product.info.main" after="page.main.title" /> 
<move element="container_product_primary_2" destination="product.info.main" after="-" /> 

<!-- Move some blocks outside the "product.info.main" to manipulate their position inside template file --> 
<move element="page.main.title" destination="product-view-wrapper" /> 
<move element="product.info.review" destination="product-view-wrapper" /> 

<!-- Product collateral data (tabs) --> 
<referenceBlock name="product.info.details" template="Infortis_Base::product/view/details.phtml" > 
<arguments> 
<argument translate="true" name="title" xsi:type="string">Kit Components</argument> 
<argument name="show_tabs" xsi:type="helper" helper="Infortis\Base\Helper\Template\Catalog\Product\View::showTabs" /> 


</arguments> 



<!-- Custom static blocks as tabs --> 
<block class="Magento\Cms\Block\Block" name="product_cms_block1" group="detailed_info"> 
<arguments> 
<argument name="block_id" xsi:type="string">block_product_tab1</argument> 
<argument name="title" xsi:type="helper" helper="Infortis\Base\Helper\Template\Catalog\Product\View::getStaticBlockTitle"> 
<param name="id">block_product_tab1</param> 
</argument> 
</arguments> 
</block> 
<block class="Magento\Cms\Block\Block" name="product_cms_block2" group="detailed_info"> 
<arguments> 
<argument name="block_id" xsi:type="string">block_product_tab2</argument> 
<argument name="title" xsi:type="helper" helper="Infortis\Base\Helper\Template\Catalog\Product\View::getStaticBlockTitle"> 
<param name="id">block_product_tab2</param> 
</argument> 
</arguments> 
</block> 
</referenceBlock> 

<referenceBlock name="catalog.product.related" > 
<action method="setTemplate"> 
<argument name="template" xsi:type="helper" helper="Infortis\Base\Helper\Template\Catalog\Product\View::getRelatedProductsTemplate" /> 


</action> 
</referenceBlock> 
<referenceBlock name="product.info.upsell" hide="true"> 
<action method="setTemplate"> 
<argument name="template" xsi:type="helper" helper="Infortis\Base\Helper\Template\Catalog\Product\View::getUpsellProductsTemplate" /> 
<!-- TODO: --> 
<argument name="is_responsive" xsi:type="string">false</argument> 
<argument name="show_items" xsi:type="string">3</argument> 
</action> 
</referenceBlock> 

<referenceBlock name="checkout.cart.crosssell" hide="true"> 
<action method="setTemplate"> 
<argument name="template" xsi:type="string">Infortis_Base::product/list/slider.phtml</argument> 
</action> 
</referenceBlock> 

<move element="reviews.tab" destination="main.content" after="-"/> 
<!-- <move element="catalog.product.related" destination="product.info.details" after="-"/> --> 


<!-- <referenceContainer name="page.wrapper"> 
<container name="extra.product.view" htmlTag="div" htmlClass="extra.product.view" > 
<container name="extra.product.view.container" htmlTag="div" htmlClass="custom-product-detail-section"> 

</container> 
</container> 
</referenceContainer> 


<move element="product.info.details" destination="extra.product.view.container" /> --> 



</body> 
</page>

After doing this image is coming on top of the page before product image. I want it to appear before tabs of description of product .

4
  • where is topattributes.phtml , in XML I don't see you called it anywhere.....got it Sep 26, 2017 at 6:06
  • @ManojDeswal this block on start of page <block class="Magento\Catalog\Block\Product\View\Attributes" template="Magento_Catalog::product/view/topattributes.phtml" name="product.info.topattribute" after="product.info.main"> </block>
    – Learner
    Sep 26, 2017 at 6:07
  • @ManojDeswal I gave destination destination="main.content" after="-" . And its at the end of page . I want to appear it before tabs and related products
    – Learner
    Sep 26, 2017 at 6:17
  • Try , the way I posted code , may be this help you... as I can't replicate it so not sure but should work Sep 26, 2017 at 6:19

1 Answer 1

3

Put below code in the end of your XML file, and remove your code you added in the top.

<referenceContainer name="product.info.main">
        <block class="Magento\Catalog\Block\Product\View\Attributes" template="Magento_Catalog::product/view/topattributes.phtml" name="product.info.topattribute" after="-"/>      
</referenceContainer>
11
  • mean just before body tag I should post this ?
    – Learner
    Sep 26, 2017 at 6:20
  • yes , as we did for reviews tab ...after this you can '<move element="reviews.tab" destination="main.content" after="-"/> ' Sep 26, 2017 at 6:21
  • let me know if it doesn't work Sep 26, 2017 at 6:43
  • work like a charm bro :D . manoj bro I have made this attribute using admin panel and by putting its type text . And enabled a wysiwyg editor . But When I upload a image using it , it gave broken link ? But When I only post code like this <p><img src="localhost/sitespy/pub/media/wysiwyg/ShopLanding-Banner.jpg" alt="" /></p> it works .
    – Learner
    Sep 26, 2017 at 6:48
  • 1
    and thank you :) this solution worked for me
    – Learner
    Sep 26, 2017 at 6:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.