I have the MageFan Awesome Blog plugin for my Magento 2 instance. I've managed to override the recent posts template by adding my own BlogOverride plugin to my vendor.
Now I am trying to override the relatedposts.phtml
file with my own code and I thought I did it the right way but nothing happened.
I first copied the file
vendor/magefan/module-blog/view/frontend/templates/catalog/product/relatedposts.phtml
to
app/code/Company/BlogOverride/view/frontend/templates/catalog/product/relatedposts.phtml
and changed the code to how I'd like it.
I then did a grep
for the relatedposts.phtml
file to see which XML file calls it, and it led me here:
vendor/magefan/module-blog/view/frontend/layout/catalog_product_view.xml
I copied it to
app/code/Company/BlogOverride/view/frontend/layout/catalog_product_view.xml
where my code looks like this:
<?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>
<referenceContainer name="content.aside">
<block class="Magefan\Blog\Block\Catalog\Product\RelatedPosts"
name="product.info.blog.relatedposts"
as="relatedposts"
before='-'
template="Company_BlogOverride::catalog/product/relatedposts.phtml" />
</referenceContainer>
</body>
</page>
I then ran:
$ php bin/magento setup:upgrade
$ php bin/magento setup:di:compile
$ php bin/magento setup:static-content:deploy -f
$ php bin/magento cache:flush
and nothing changed, it's still using the default relatedposts.phtml
file. How can I override files created by external plugins?
Edit: I've tried the below suggested answer to no avail:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceBlock name="content.aside">
<action method="setTemplate">
<argument name="template" xsi:type="string">Company_BlogOverride::catalog/product/relatedposts.phtml</argument>
</action>
</referenceBlock>
</page>