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.
2 Answers 2
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>
-
use this code in phtml file to call your attributeAfzel Arshad– Afzel Arshad2022年05月11日 13:46:54 +00:00Commented 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.Andyjw– Andyjw2022年05月12日 08:38:55 +00:00Commented May 12, 2022 at 8:38
-
please let us know when you find your answerAfzel Arshad– Afzel Arshad2022年05月13日 06:00:05 +00:00Commented 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.Andyjw– Andyjw2022年05月18日 08:42:17 +00:00Commented May 18, 2022 at 8:42
-
In the end we had to create a module to achieve this.Andyjw– Andyjw2023年01月26日 09:55:07 +00:00Commented Jan 26, 2023 at 9:55
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.
-
Any chance this code/module is publicly available on GitHub?Jory Hogeveen– Jory Hogeveen2023年09月15日 09:11:26 +00:00Commented 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.Andyjw– Andyjw2023年09月19日 08:34:44 +00:00Commented Sep 19, 2023 at 8:34
Explore related questions
See similar questions with these tags.