1

Magento2 How can I display page builder product custom attribute value in custom PHTML file.

In short, I have created a product custom attribute of type page builder in admin & I want its value to be displayed in frontend (from custom.phtml)

How can I achieve that?

1 Answer 1

0

I've done a similar thing (mind this is a product attribute) in phtml file:

<?php
declare(strict_types=1);

use Hyva\Theme\Model\ViewModelRegistry;
use Magento\Catalog\Model\Product;
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;
use Hyva\Theme\ViewModel\ProductPage;

/** @var Escaper $escaper */
/** @var Template $block */
/** @var ViewModelRegistry $viewModels */

/** @var ProductPage $productViewModel */
$productViewModel = $viewModels->require(ProductPage::class);
/** @var Product $product */
$product = $productViewModel->getProduct();

if (!$product->getYourAttributeIdentifier()) {
    return;
}
?>



<div>
<?= $productViewModel->productAttributeHtml($product, $product->getYourAttributeIdentifier(), 'your_attribute_identifier') ?>
</div>

replace "your attribute identifier" with what you need and you're done! :) if it's not empty it will show

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.