I have to create new layout on product view page using xml on the bases of product attribute set......
Trying this but no luck: layout/catalog_product_view_attribute_set_id_10.xml
Any idea to achieve this?
Using a custom module, you can create a plugin for the Magento\Catalog\Helper\Product\View
class's initProductLayout
method.
Your plugin class would be something like this:
use Magento\Catalog\Model\Product;
use Magento\Framework\View\Result\Page as ResultPage;
class View
{
public function beforeInitProductLayout(
\Magento\Catalog\Helper\Product\View $subject,
ResultPage $resultPage, Product $product, $params = null
) {
$resultPage->addPageLayoutHandles(
['attribute_set_id' => $product->getAttributeSetId()]
);
return [$resultPage, $product, $params];
}
}
Then catalog_product_view_attribute_set_id_10.xml
will be included for products that use attribute set 10.