Display Product Attributes in CMS Block or Page Builder – Magento2 Guide

cms-blockmagento2page-builderproduct-attributevariables

I need to be able to reference product attributes inside a cms block or page builder, I am not wanting to create any template files I am wanting to call it like you can call a variable.

So here is one of Magento's standard variables which outputs the base url from the config.

{{config path="web/unsecure/base_url"}}

What I need to know is there anyway you can do this for product attributes.

Or if someone knows how to create a set of custom variables which call the data from a product attribute would be great.

Best Answer

use this code in phtml file to call your attribute –

<?php
/**
 * @var Magento\Catalog\Block\Product\View $block
 */
$product = $block->getProduct();
?>
<h1 style="color: #1979c3">Brand:<?php echo $product->getData('brand'); ?></h1>
Related Topic