magento2 - 在 Magento 2 中,如何从布局中检索容器?

标签 magento2 magento-layout-xml

如何以编程方式从布局中检索容器?

我希望能够执行以下操作...

$container = $layout->getContainer('name');
$container->setAttribute('htmlClass', 'class');

最佳答案

所以我就是那个人,尽量不要直接使用对象管理器。 To use or not to use the ObjectManager directly?

<?= $block->getLayout()->renderNonCachedElement('top-right-wrapper'); ?>
-or-
<?= $this->getLayout()->renderNonCachedElement('top-right-wrapper'); ?>

以上两个都可以使用,但不鼓励使用 $this。 Magento 2 Templates: Use $block or $this ?

关于magento2 - 在 Magento 2 中,如何从布局中检索容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38012953/

相关文章:

rest - 如何正确发出 REST API 请求以获取 Magento 2 中日期范围内的完整订单

php - Magento 2 - di.xml 虚拟类型 - 覆盖一个类

magento - 通过布局 XML 文件向 Helper 类传递参数

magento - 如何将脚本和 CSS 挂接到 <head> 中?

magento2 - 获取 URL 参数并应用于 UI 组件中的按钮

php - Magento 2 基于产品属性过滤运输方式

collections - 根据 final_price 获取 Magento 2 集合

magento - 在 Magento 皮肤 Javascript 之前加载外部 Javascript

xml - Magento 模块布局 xml 加载顺序