1

I'm trying to pass a helper as parameter for attribute class in layout XML, like I did sometimes in M1.

The layout XML currently looks like:

<body>
   <attribute name="class">
            <argument name="value" xsi:type="helper" helper="Company\Module\Helper\Data::getCssNameRegion"/>
   </attribute>
</body>

The helper will return a string like "region-us", "region-uk", and so on.

I'm just trying to make <attribute name="class" value="FROMHELPER"/> bring the value from there.

How to do that in M2?

In this other question the user asks about other kind of usage, but I was unable to replicate for attribute node.

0

1 Answer 1

0

What I did to workaround the situation was use core/text block and add a JS to add the class. Poor, but didn't find a better solution yet.

    <referenceContainer name="after.body.start">
        <block class="Magento\Framework\View\Element\Text" name="bodyClassScript">
            <action method="setText">
                <argument name="value" xsi:type="helper" helper="Company\Module\Helper\Data::getJsRegion"/>
            </action>
        </block>
    </referenceContainer>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.