markshust/magento2-module-messages

消息模块允许您使用HTML发送成功、通知、警告和错误消息。

资助包维护!
markshust

安装: 34

依赖项: 0

建议者: 0

安全: 0

星级: 57

观察者: 5

分支: 17

开放问题: 1

类型:magento2-module

1.0.0 2018-11-06 21:29 UTC

This package is auto-updated.

Last update: 2024-09-13 16:54:06 UTC


README

使用<html>发送成功、通知、警告和错误消息

Supported Magento Versions Latest Stable Version Composer Downloads Maintained - Yes

目录

摘要

默认情况下,当你在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'],
]);

Screenshot

许可

MIT