cancel
Showing results for 
Search instead for 
Did you mean: 

Loading a new block on page

Loading a new block on page

In Magento 2 admin page, content I created a new page.
Then I created a new block that have a simple html as content.
I'd like to load this new block in my page, then I go in "page edit" on "Design", "Layout update XML" textbox and try to insert this xml:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceBlock name="content">
        <block type="page/html" name="my-block-id" />
    </referenceBlock>
</page>

but this does not work cause nothing happens.
How to make block is loaded in the page?
Could someone share a simple example for make it works?

Thanks in advance.

2 REPLIES

Re: Loading a new block on page

You are using the Magento 1.x syntax which does not work in Magento 2.

How to add a block to a Magento 2 page by a layout directive: https://mage2.pro/t/305

Re: Loading a new block on page

Maybe I explained bad .. or maybe I'm not understanding how it works, but unfortunately I do not know already Magento (never used Magento 1 and now I'm trying to learn Magento 2).
I created a new block in the content admin page .. in the content of block I wrote "<p> hello </ p>" ... as id assigned "my-block-id"
then I created new page.. in "Design" at "XML layout update" I try to load that block..
for do that now I try to write this Xml but nothing appens... is this Xml right?
(I don't know if I have to specified a "class" attribute.. which attribute and why?.. excuse me but I don't understand)

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block type="page/html" name="my-block-id" />
        </referenceContainer>
    </body>
</page>