4

I created a static block in backend of my magento and now i would like to recall the created block in the footer, near to the footer link .

In what phtml files I retrieve it?

Thanks.

P.S. Where is the file of footer links for change the link and name?

11

From templates you can simply call static block by
<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>
Links in footer generate by layout in module Magento_Theme

<referenceContainer name="footer-container">
        <container name="footer" as="footer" label="Page Footer" htmlTag="div" htmlClass="footer content">
            <block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" template="switch/stores.phtml"/>
            <block class="Magento\Framework\View\Element\Html\Links" name="footer_links">
                <arguments>
                    <argument name="css_class" xsi:type="string">footer links</argument>
                </arguments>
            </block>
            <block class="Magento\Theme\Block\Html\Footer" name="copyright" template="html/copyright.phtml"/>
            <block class="Magento\Framework\View\Element\Template" name="report.bugs" template="Magento_Theme::html/bugreport.phtml" />
        </container>
    </referenceContainer>
  • Thanks man, i tried this but what is the file of the footer where i can call my static block? I try to paste this code in html/footer.phtml in Magento_Theme but not function...why? – Gabriel91 Feb 9 '16 at 16:18
  • You should enable path hint from backend to find right files to modify. Basiclly theme merchanism fallback will find required files in your current active theme, if it fail it will try to find from parent theme if fail it will find in core modules – mrtuvn Feb 11 '16 at 5:36
2

Or from any code location with the block id:-

class MyBlock
{
    /**
     * @var \Magento\Cms\Model\Template\FilterProvider
     */
    protected $_filterProvider;

    /**
     * Store manager
     *
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $_storeManager;

    /**
     * Block factory
     *
     * @var \Magento\Cms\Model\Block
     */
    protected $_block;

    /**
     * @param Magento\Framework\View\Element\Template\Context $context
     * @param Magento\Store\Model\StoreManagerInterface $storeManager,
     * @param Magento\Cms\Model\Template\FilterProvider $filterProvider,
     * @param Magento\Cms\Model\BlockFactory $blockFactory,
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Cms\Model\Template\FilterProvider $filterProvider,
        \Magento\Cms\Model\BlockFactory $blockFactory,
        array $data = []
    ) {
        $this->_storeManager = $storeManager;
        $this->_filterProvider = $filterProvider;
        $this->_block = $blockFactory->create()->setStoreId(
                               $storeManager->getStore()->getId()
                          );
        parent::__construct($context, $data);
    }

    /**
     * @return string
     */
    protected function getHtml() {
        $html = '';
        if($this->getCustomBlockId()){
            $this->_block->load($this->getCustomBlockId());
            if($this->_block->isActive())
                $html = $this->_filterProvider->getBlockFilter()->setStoreId(
                           $this->_storeManager->getStore()->getId()
                         )->filter($this->_block->getContent());
        }
        return $html;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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