markshust / magento2-module-messages
消息模块允许您使用HTML发送成功、通知、警告和错误消息。
1.0.0
2018-11-06 21:29 UTC
Requires
- php: >=7.1
- magento/framework: 101.0.*
This package is auto-updated.
Last update: 2024-09-13 16:54:06 UTC
README
使用<html>
发送成功、通知、警告和错误消息
目录
摘要
默认情况下,当你在Magento中调用$this->messageManager->addSuccessMessage
时,你不能传递自定义HTML到你的消息中。这不会给你提供向访客提供定制消息的灵活性。
此模块提供了显示自定义消息的能力,包括HTML,同时仍然转义HTML以防止跨站脚本(XSS)攻击。
安装
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);
使用说明
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'], ]);