Magento 2: How to call PHP file in another phtml file inside the module?
-
15-04-2021 - |
문제
I am using magefan blog extension, i want to move post page bottom section related product to sidebar
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,
The related product php file under \app\code\Magefan\Blog\Block\Post\View\RelatedProducts.php how to call this file into side bar section?
해결책
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>
다른 팁
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();
?>
제휴하지 않습니다 magento.stackexchange