I created front end model for custom product attribute.but

in the front end output coming like this <b>pencilval</b> instead of pencilval

namespace Some\Pencil\Model\Entity\Attribute\Frontend;

    class Pencil extends \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend
         * Retrieve attribute value
         * @param \Magento\Framework\DataObject $object
         * @return mixed
        public function getValue(\Magento\Framework\DataObject $object)
            $data = '';
            $value = parent::getValue($object);
            if ($value) {
                $data = '<b>' . $value . '</b>';
            return $data;

If you are relying on showing your new attribute in the "Additional Data" section of the product detail page, what you are trying will not be possible. Here is why:

The value that is returned from getValue() will always be escaped. There is also no way to change the styling of the for a single attribute without changing the attributes.phtml itself:

<?php if ($_additional = $block->getAdditionalData()): ?>
<div class="additional-attributes-wrapper table-wrapper">
    <table class="data table additional-attributes" id="product-attribute-specs-table">
        <caption class="table-caption"><?php echo __('More Information') ?></caption>
        <?php foreach ($_additional as $_data): ?>
                <th class="col label" scope="row"><?php echo $block->escapeHtml(__($_data['label'])) ?></th>
                <td class="col data" data-th="<?php echo $block->escapeHtml(__($_data['label'])) ?>"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
        <?php endforeach; ?>
| improve this answer | |

You should set up is_html_allowed_on_front flag in installer script for your custom attribute or add this at the beginning of your getValue method

$this->getAttribute()->setData(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::IS_HTML_ALLOWED_ON_FRONT, 1);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.