Is there any way to add a simple php code:
<div title="<?php echo $_product->getAttributeText("manufacturer"); ?>"></div>
to a block we create under content page. It can't execute PHP code as far as I'm concerned.
Is there any way to add a simple php code:
<div title="<?php echo $_product->getAttributeText("manufacturer"); ?>"></div>
to a block we create under content page. It can't execute PHP code as far as I'm concerned.
I assume that you want to call PHP code in a static block.
You can do so by calling a phtml file in the static block and write your PHP code in the phtml file.
To call phtml file in static block, you need to write code like this:
{{block class="Path\To\Block\Class" template="Namespace_Module::filename.phtml"}}
Since you are trying to get product manufacturer, I think you need to use block class name as Magento\Catalog\Block\Product
.
You cannot add PHP code into static blocks
but you can add a link to your phtml file into static block
Then add this file into the static file as
{{block type="core/template" template="catalog/category/sample.phtml"}}
The following syntax will help you:
Basically, you need to call .phtml file to execute your php file or php code;
{{block class="path-to-block-class" template="module-name::your-filename.phtml"}}
Please try the below instead of your code:
<div title="<?= $_product->getAttributeText("manufacturer"); ?>"></div>
phtml
extension.
Jun 14, 2018 at 11:46
Your above code has small mistake, which is you are including double quote inside another double quote. Replace your code with the below code:
<div title="<?php echo $_product->getAttributeText('manufacturer'); ?>"></div>