1

I try to add a new container to my layout. The container needs the attribute data-block='minicart'

<container name="minicart-wrapper" htmlTag="div" htmlClass="minicart-wrapper" data-block='minicart'/>

If I try this I get

Element 'container', attribute 'data-block': The attribute 'data-block' is not allowed.

More Code:

<referenceContainer name="header-wrapper">
    <container name="header-row" label="Header Bootstrap" as="header-row" htmlTag="div" htmlClass="row">

        <container name="header-row-col-a" htmlTag="div" htmlClass="col-2"/>
        <container name="header-row-col-b" htmlTag="div" htmlClass="col-7"/>
        <container name="header-row-col-c" htmlTag="div" htmlClass="col-3">

            <container name="minicart-row" label="Wrapper" htmlTag="div" htmlClass="row no-gutters minicart-wrapper">  <--- Need data-block="minicart" here

                <container name="mini-wk" label="Top" htmlTag="div" htmlClass="col-9 offset-3 mini-wk">

                    <container name="mini-wk-top" label="Top" htmlTag="div" htmlClass="mini-wk-top">
                        <container name="mini-wk-top-row" label="Top Row" htmlTag="div" htmlClass="row no-gutters">

                            <container name="mini-wk-top-row-col-a" label="Benutzerkonto" htmlTag="div" htmlClass="col-6"/>
                            <container name="mini-wk-top-row-col-b" label="Anmelden/Abmelden" htmlTag="div" htmlClass="col-6"/>
                        </container>
                    </container>

                    <container name="mini-wk-content" label="Minicart-Main" htmlTag="div" htmlClass="mini-wk-content row no-gutters"/>
                </container>
            </container>
        </container>
    </container>
</referenceContainer>
1

This is not possible in core Magento 2, the container node only supports these attributes:

  • name
  • label
  • before
  • after
  • as
  • output
  • htmlTag
  • htmlId
  • htmlClass

You would need to load a template inside that container and add your attribute there.

0

You should Try

<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
    <css src="Vendor_ModuleName::css/style.css"/>
</head>
   <body>
        <attribute name="class" value="new-class-name"/>
        <attribute name="data-block" value="minicart"/>
    </body>
</page>

[Update answer for add attribute ]

use jQuery to add attibute to your container

please use container class name to add atrribute

$('.minicart-wrapper').attr("data-block", "minicart");

I hope it helps you

12
  • @BenCrook is right here is alternative way to do – Msquare Jan 17 '20 at 11:56
  • Why update handle customer_account ? – Black Jan 17 '20 at 12:25
  • @Black this is used in Customer Dashboard. Here it's not Require. I update my Answer. – Msquare Jan 17 '20 at 13:58
  • I don't understand. How is this code supposed to add the attribute data-block to my container with name minicart-wrapper ? – Black Jan 17 '20 at 14:04
  • @Black BenCrook already said It's not possible in Magento , Here I am show add attribute in Main Body Tag of This Layout only , and other is You would need to load a template inside that container and add your attribute there. – Msquare Jan 17 '20 at 14:45

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.