1

I have a custom phtml file that I've included on the homepage, this has several divs that call in static blocks. Here is a simplified version:

<div class="my-div-1">
    <?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('my_block_1')->toHtml();?>       
</div>

<div class="my-div-2">
    <?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('my_block_1')->toHtml();?>       
</div>

And here is how I've called it in on the homepage:

<referenceContainer name="main">
  <block class="Magento\Framework\View\Element\Template" name="homepage_content" template="Magento_Cms::homepage-content.phtml" />
</referenceContainer>

In my cms_index_index.xml I want to move the cms content block between .my-div-1 and .my-div-2 but I'm struggling to get the right reference. I currently have it wrapped in a div as follows:

<referenceContainer name='content'>
  <container name='homepage-section' as='homepage-section' htmlTag='div' htmlClass='homepage-section cms' />
</referenceContainer>
<move element='cms_page' destination='homepage-section'/>

Can someone help me with moving this between my 2 divs please, or can it not be done?

3
  • You could try splitting your custom phtml into to e.g. hometop.phtml and homebottom.phtml. Then adding one block to the top of content and one to the bottom of content?
    – harri
    Commented Nov 16, 2017 at 14:58
  • Of course, why didn't I think of that! Cheers, I'll give it a go now!
    – Ordog
    Commented Nov 16, 2017 at 15:17
  • After a bit more cursing I've done it. Thanks again for your help. If you want to put it as an answer I'll accept it :)
    – Ordog
    Commented Nov 16, 2017 at 15:34

1 Answer 1

1

I would split your custom phtml into 2 e.g. hometop.phtml and homebottom.phtml.

Then add one block to the top of content and one to the bottom of content.

Your Answer

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

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