0

I'm struggling around trying allowing html tags in order/invoice comments which are sending out to customer via transaction emails.

What i did:

{{var comment |raw}}

Edited the comment variable, removing the |escape|nl2br tags and adding the |raw tag. In my understanding the raw tag is for allowing html without beeing striped out, but it's not working.

Any ideas?

3

By default Magento does not allow html tags in the order comments. It's in the controller that handles the comments.

Take a look in vendor/magento/module-sales/Controller/Adminhtml/Order/AddComment.php. There is a line which trims html tags.

$comment = trim(strip_tags($data['comment']));

So if you want tags in comments you need to rewrite the method execute. Follow the steps mentioned here to override the controller in your custom module.

You will have to override the phtml file as well if you wish to display comments on frontend.

vendor/magento/module-sales/view/frontend/templates/order/comments.phtml

and change this line:

<dd class="comment text"><?php echo $block->escapeHtml($_commentItem->getComment()) ?></dd>

Hope it helps!

| improve this answer | |
  • hey @sejal. thx for your feedback, it heped me a bit out. now the frontend is rendering fine in customer account. the comments are added incl. html to the database though the strip_tags. i still face the issue that the comment in the transactional mail has no html tags. i think i have to check the output of the variable comment but i cannot find the code – Florin P. Jul 26 '17 at 9:30

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.