加载自定义插件商店页面的布局

huangapple go评论53阅读模式
英文:

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>

huangapple
  • 本文由 发表于 2023年5月10日 17:08:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76216684.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定