Magento 2 – How to Call Custom Module on Home Page

custommagento-2.1module

I have created a custom module with view using (Block, Layouts and Templates), its working fine with the url(http://hostname/modulename/index/test) but need to call it in home page. I mean when home page loaded, module should be rendering in home page in specific area with following fields (Name, age-group, gender etc.). And also have to save these fields values in database.

Steps followed during creation of module without view :

Step 1: Created the Namespace(CompanyName) and module(HelloWorld) folder

Step 2: Created etc/module.xml file

Step 3: Created etc/registration.php file

Step 4: Created etc/frontend/routes.xml file

Step 5: Created Controller/Index/Display.php

Steps followed during creation of module with view :

Step 1: Created layout – view/frontend/layout/helloworld_index_display.xml

Step 2: Created block – app/code/CompanyName/HelloWorld/Block/Display.php

Step 3: Created template file – app/code/CompanyName/HelloWorld/view/frontend/templates/sayhello.phtml

Everything is working fine just I have to render sayhello.phtml file in Homepage area. How I can do this?

Thanks.

Best Answer

Admin panel, Content -> Pages -> Select Home Page (as per Store view) -> here add

    {{block class="CompanyName\\HelloWorld\\Block\\Display" template="CompanyName_HelloWorld::sayhello.phtml"}}

This can help!!

Related Topic