Unfortunately, there's no way you can do this via XML out of the box.
Magento 2 handles the htmlTag
, htmlId
and htmlClass
via the Magento/Framework/View/Layout.php
file under the _renderContainer
method:
protected function _renderContainer($name)
{
$html = '';
$children = $this->getChildNames($name);
foreach ($children as $child) {
$html .= $this->renderElement($child);
}
if ($html == '' || !$this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG)) {
return $html;
}
$htmlId = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_ID);
if ($htmlId) {
$htmlId = ' id="' . $htmlId . '"';
}
$htmlClass = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_CLASS);
if ($htmlClass) {
$htmlClass = ' class="' . $htmlClass . '"';
}
$htmlTag = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG);
$html = sprintf('<%1$s%2$s%3$s>%4$s</%1$s>', $htmlTag, $htmlId, $htmlClass, $html);
return $html;
}
As you can see, this method does not render any extra attributes than the ones I mentionned.
A alternative would be to use JavaScript to add the attribute based on the id you've given to your tag, for example:
jQuery('#customContainer').attr('customAttribute','customValue);
So looks like you can't move an element which has been removed using xml. Simply commenting out the following:
<container name="header.panel.wrapper" remove="true" />
And making sure this is pointing at the correct block:
<move element="top.links" destination="header.top.actions" before="-" />
Will move the block into the correct area. Hope this helps people if they come across the same issue.
Best Answer
Inside your
default.xml
In the test.phtml
Out put
Sample module
/app/code/Vendor/Module/registration.php
/app/code/Vendor/Module/etc/module.xml
/app/code/Vendor/Module/view/frontend/layout/default.xml
/app/code/Vendor/Module/view/frontend/templates/test.phtml