2

I've followed this tutorial: https://store.fooman.co.nz/blog/displaying-complex-error-messages-in-magento-2.html

This is my di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\View\Element\Message\MessageConfigurationsPool">
        <arguments>
            <argument name="configurationsMap" xsi:type="array">
                <item name="PortailAxiane" xsi:type="array">
                    <item name="renderer" xsi:type="const">\Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE</item>
                    <item name="data" xsi:type="array">
                        <item name="template" xsi:type="string">Portail_Axiane::custommessage.phtml</item>
                    </item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

This is my custommessage.phtml

<?php echo $block->escapeUrl($block->getData('url'))?>

And my message in my observer :

$this->_messageManager->addComplexErrorMessage(
                        'PortailAxiane',
                        array(
                            "url" => $produtToAddUrl
                        ), null
                    );

But as the result, I only have the red rectangle. What did I missed ?

  • I think you should check var/log exception.log and system.log files – Hitesh Oct 10 '18 at 9:05
  • No exceptions inside – Morgan Tartreau Oct 10 '18 at 9:12
1

It appears code relating to messaging needs to go in the view you wish to add it to. So ensure your di.xml file is located at:

etc/frontend/di.xml or etc/adminhtml/di.xml

instead of just etc/di.xml

1

Mark Shust's answer worked for me.
So you need to create another one di.xml in etc/frontend or etc/backend (depending on what area you need) folder of your module.
And then add this code to it.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\View\Element\Message\MessageConfigurationsPool">
        <arguments>
            <argument name="configurationsMap" xsi:type="array">
                <item name="identifierName" xsi:type="array">
                    <item name="renderer" xsi:type="const">\Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE</item>
                    <item name="data" xsi:type="array">
                        <item name="template" xsi:type="string">Vendor_Module::messages/example-message.phtml</item>
                    </item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

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.