cancel
Showing results for 
Search instead for 
Did you mean: 

CMS Block in layout with template

CMS Block in layout with template

Hi,

I want to use a template file to output a cms block in my layout footer.

this is the layout xml

<block class="Magento\Cms\Block\Block" name="store.footer.col.3" template="Magento_Theme::html/footer_links_block.phtml" after="store.footer.col.2">
<arguments>
<argument name="block_id" xsi:type="string">footer_links_block</argument>
</arguments>
</block>

 this is the template html.

<div class="cell small-12 medium-4 large-3 footer-links-block <?= /* @escapeNotVerified */ $block->getBlockCss() ?>">
    <h4 class="h6"><?= /* @escapeNotVerified */ $block->getBlockTitle() ?></h4>
	<?= $block->getChildHtml() ?>
</div>

It seems that the template call in the xml is ignoring that i want the use the template to render it.

What am I doing wrong?

on a another note what are the best books to learn magento dev, I'm an experienced php dev but this is my first project with magento.

 

Cheers

Kev

1 REPLY 1

Re: CMS Block in layout with template

Hi @journeyman_73 

From what I can see in your template, the variable

$block

is equal to 

 

Magento\Cms\Block\Block

 so

$block->getBlockCss()
$block->getBlockTitle()

need to be methods / functions defined in: 

 

Magento\Cms\Block\Block.php

 

Regarding the CMS block you are trying to render with:

<?= $block->getChildHtml() ?>

Try creating another block child of the one you already have. Something like this:

<block name="store.footer.col.3" template="Magento_Theme::html/footer_links_block.phtml" after="store.footer.col.2">
<block class="Magento\Cms\Block\Block" name="store.footer.col.3">
<arguments>
<argument name="block_id" xsi:type="string">footer_links_block</argument>
</arguments>
</block>
</block>

Hope it helps