- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2019
08:19 AM
01-20-2019
08:19 AM
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
Labels:
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020
06:46 PM
02-28-2020
06:46 PM
Re: CMS Block in layout with template
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