MarkShust_Messages
markshust/magento2-module-messages
This extensions allows us to send success, notice, warning, and error messages with embedded HTML.
Build Tests
Code Quality
Tested on Magento 2.4.8-p3
Recent Test History
Each release is tested against the latest Magento version at that time.
+4 older tests
Looking for Contributors
Composer installation fails. Your contribution could help the entire Magento community!
Share This Module's Status
README
Loaded from GitHubTable of contents
Summary
By default, when you call $this->messageManager->addSuccessMessage within Magento, you cannot pass custom HTML into your message. This doesn't provide you with the flexibility to provide customized messages to your visitors.
This module provides the ability to display custom messages including HTML, and still escapes the HTML to prevent cross-site scripting (XSS) attacks.
Installation
composer require markshust/magento2-module-messages
bin/magento module:enable MarkShust_Messages
bin/magento setup:upgrade
API
/**
* Any of the built-in complex message functions can be called with this identifer:
* addComplexSuccessMessage
* addComplexNoticeMessage
* addComplexWarningMessage
* addComplexErrorMessage
*
* @param string $identifer Set to 'withHtml' to use this module.
* @param mixed[] $data Data containing elements.
* @type string 'html' Desired output including HTML.
* @type string[] 'allowed_tags' (optional) List of allowed tags to render as HTML.
*/
$this->messageManager->addComplexSuccessMessage($identifer, $data);
Usage
protected messageManager;
public function __construct(
...
\Magento\Framework\Message\ManagerInterface $messageManager,
...
) {
$this->messageManager = $messageManager;
...
}
$this->messageManager->addComplexSuccessMessage('withHtml', [
'html' => '<b>This is bold text!</b> And this is not.',
'allowed_tags' => ['b'],
]);

License
This content is fetched directly from the module's GitHub repository. We are not the authors of this content and take no responsibility for its accuracy, completeness, or any consequences arising from its use.