0

Magento 2: I'm trying to add a block to a cms page with a layout overwrite. The problem is the url key has a / at the end which can not be removed. So the url key is uber-uns/ If i remove the / as a TEST it works. Any one got a clue how i do this and keep the /?

app/design/frontend/Company/theme-shopname/Magento_Cms/layout/cms_page_view_id_uber-uns.xml (this works as a test without /) (file content isn't really relevant for the question)

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="../../../../../vendor/magento/framework/Module/etc/module.xsd">
    <body>
        <referenceContainer name="main">
            <container name="home-blocks" htmlTag="div" htmlClass="home-blocks">
                <container name="home-blocks-right-wrapper" htmlTag="div" htmlClass="home-blocks-right-wrapper"
                           after="-">
                    <container name="home-block-2-wrapper" htmlTag="div" htmlClass="home-block-2 movies-left"
                               before="-">
                        <block class="Company\HomePageVideo\Block\HomeVideo" name="block-movies-left"
                               template="Company_HomePageVideo::homepage-video.phtml">
                            <container name="home-block-2-text" htmlTag="div" htmlClass="home-block-2-text">
                                <block class="Magento\Cms\Block\Block" name="home-block-2">
                                    <arguments>
                                        <argument name="block_id" xsi:type="string">home-block-2</argument>
                                    </arguments>
                                </block>
                            </container>
                        </block>
                    </container>
                </container>
            </container>
        </referenceContainer>
    </body>
</page>

2 Answers 2

0

1)From layout .xml file:

<block class="Magento\Cms\Block\Block" name="Promo">
    <arguments>
        <argument name="block_id" xsi:type="string">promo</argument>
    </arguments>
</block>

2)From .Phtml File:

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>

3)From cms page or block:

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}

I hope this may help you.

0

I wasn't able to figure it out. So i ended up making a html block and adding it to the specific page with the pagebuilder.

{{block class="Company\HomePageVideo\Block\HomeVideo" name="over-ons-video" template="Company_HomePageVideo::over-ons-video.phtml" area="frontend"}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.