How to add Custom table next to product attribute in a product detail page
1 Answer
Create a Block in Admin site (like: Identifier is 'table') add HTML tags what u want.
Create a file, name is table.phtml
app/design/frontend/vendor/Theme/Magento_Catalog/templates/product/view/table.phtml
<?php
echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('table')->toHtml();
?>
Then call the file in catalog_product_view.xml
app/design/frontend/vendor/Theme/Magento_Catalog/layout/catalog_product_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<block class="Magento\Catalog\Block\Product\View" name="table"
template="Magento_Catalog::product/view/table.phtml" >
</block>
<move element="table" destination="product.info.main" after="product.info.stock.sku"/>
</page>
After that running these commands:
sudo php bin/magento setup:upgrade
sudo php bin/magento setup:di:compile
sudo php bin/magento cache:clean
sudo php bin/magento cache:flush