英文:
Load a layout in my custom plugin storefront page
问题
你可以在控制器中使用以下代码加载创建的布局:
$this->renderStorefront('your_layout_name', [], $request);
请确保将your_layout_name
替换为你创建的布局的名称。
英文:
I have a custom plugin built for Shopware 6. I created a new route /certificate
with a certificate.html.twig
view to show a list of the custom entity along with other html contents.
I want to be able to edit the HTML contents of this page (not the list) from the administration area, so I went to 'Content' > 'Shopping Experience' and created a custom layout.
I inserted my HTML tags as text type (in the source code interface).
The problem: I want to link this created layout with the custom twig template I created (or any other approach to make this HTML content editable from the administration).
How to load the layout in my controller at least?
答案1
得分: 1
在您的控制器中,您使用您购物体验布局的ID检索了cms_page
实体,然后将其传递给模板。
在您的自定义模板中,您可以包含用于呈现购物体验的模板。
英文:
In your controller you fetch the cms_page
entity with the id of your shopping experience layout. You then pass it to your template
$criteria = new Criteria([$cmsPageId]);
$criteria->addAssociation('sections.blocks');
$cmsPage = $this->container->get('cms_page.repository')->search($criteria, $context)->first();
return $this->renderStorefront('@MyPlugin/storefront/page/certificate/certificate.html.twig', ['cmsPage' => $cmsPage]);
In your custom template you can then include the template for rendering the shopping experience.
{% set cmsPageClasses = ('cms-page ' ~ cmsPage.cssClass|striptags)|trim %}
<div class="{{ cmsPageClasses }}">
{% sw_include "@Storefront/storefront/page/content/detail.html.twig" with {'cmsPage': cmsPage} %}
</div>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论