Question

I am using magefan blog extension, i want to move post page bottom section related product to sidebar

enter image description here

I have created custom phtml file based on the side bar postion under app\code\Magefan\Blog\view\frontend\templates\sidebar\related_products.phtml

<?php 
echo "hell hello";
?>

The output,

enter image description here

The related product php file under \app\code\Magefan\Blog\Block\Post\View\RelatedProducts.php how to call this file into side bar section?

Was it helpful?

Solution

You want to do this via XML.

In app/design/frontend/[Vendor]/[theme]/Magefan_Blog/layout/blog_post_view.xml

add:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <move element="blog.post.relatedproducts" destination="blog.sidebar" after="blog.sidebar.search"/>
    </body>
</page>

OTHER TIPS

To call a block file in phtml, you can do like this.

<?php
$blockObj= $block->getLayout()->createBlock('Magefan\Blog\Block\Post\View\RelatedProducts');
echo $blockObj->getAnyMethod();
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top