0

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.

asked May 11, 2022 at 11:48

2 Answers 2

0

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>
Gohil Rajesh
3,1201 gold badge15 silver badges26 bronze badges
answered May 11, 2022 at 13:46
5
  • use this code in phtml file to call your attribute Commented May 11, 2022 at 13:46
  • As per my question I don't want this done in a phtml file but inside a cms block as I already know how to achieve this in a phtml file, but thanks for the response. Commented May 12, 2022 at 8:38
  • please let us know when you find your answer Commented May 13, 2022 at 6:00
  • seems like I am going to have to make a module to achieve this, would have thought you would be able to call these easily. Commented May 18, 2022 at 8:42
  • In the end we had to create a module to achieve this. Commented Jan 26, 2023 at 9:55
0

So in the end we created a custom module which you could call the attributes via a widget into page builder or any content blocks.

answered Jan 26, 2023 at 10:01
2
  • Any chance this code/module is publicly available on GitHub? Commented Sep 15, 2023 at 9:11
  • Currently there is no GitHub repo for this but I will see if the company I work for will allow this to be shared. Commented Sep 19, 2023 at 8:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.