1

I have phtml file at

app/code/Vendor/Module/view/frontend/template/content.phtml

How can I make it to change homepage?

I have module.xml file and registration.php file as well. Module is installed.

I suppose that I have to make Block and Controller, but can't get it right.

In wich directories and what files I should make that content.phtml file could make changes to homepage?

1
  • I've given answer and if you require any other information. Please ping here. Thanks Feb 19, 2019 at 13:24

1 Answer 1

4

In order display simple content in home page it doesn't require Block or Controller instead you follow these steps to display content in home page.

Firstly, you need to change template to templates.

then

Add cms_index_index.xml in vendor/module/view/frontend/layout/cms_index_index.xml

then add the following code to the xml

<?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">
        <block class="Magento\Framework\View\Element\Template" name="test" template="vendor_module::content.phtml"></block>
    </referenceContainer>
</body>

and you can locate your content to specific place in home page by adding these parameters to block element.

you may use before="before.body.end" or after="before.body.start or after.body.start" etc..,

If you want to display any dynamic content which loads from database then you require block to load data.

Hope this helps. Peace :)

2
  • Thank's!!! It really helped!
    – Rufus
    Feb 19, 2019 at 13:30
  • upvoted ;) But you are missing the closing tag </page> Oct 22, 2020 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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