문제

I have created a block programmatically which shows category name and image on home page. Following is my code:

cms_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block name="homepage.category.thumbnail"
                   class="Magento\Framework\View\Element\Template"
                   template="Vendor_CategoryCms::list.phtml">
                <arguments>
                    <argument name="category_list" xsi:type="object">\Vendor\CategoryCms\ViewModel\CategoryList</argument>
                </arguments>
            </block>
        </referenceContainer>
    </body>
</page>

This block taking data from viewmodal and showing in phtml file. If I need to place it on any other page, I need to override that page layout. Is there any way to convert this block to cms block so that we can place it anywhere from admin panel?

올바른 솔루션이 없습니다

다른 팁

If you want to add your block to a CMS page, you can add your block into HTML content like below. Otherwise, you know you can add the block XML to any layout file, as you did for the homepage.

<div class="someclass">{{block class="Magento\Framework\View\Element\Template" name="homepage.category.thumbnail" template="Ktpl_CategoryCms::list.phtml" category_list="\Ktpl\CategoryCms\ViewModel\CategoryList"}}</div>

Hope this helps.

It can be achieve by creating widget.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top