0

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.

  • please provide more information regarding your module and what you have try. – Gopal Patel Mar 3 '18 at 7:51
  • I have created a custom module, its working fine with the url(host/modulename/index/test) but need to call it on home page. I mean when home page loaded, module should be called automatically. Step 1: Created the Namespace and module 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/Test.php – Md Amanullah Mar 3 '18 at 7:59
  • Can you be more specific ? Is that for getting the data or rendering a view and then append to homepage ? – Toan Tam Mar 3 '18 at 8:53
  • Yes, I want to rendering a view with following fields (Name, age-group, gender etc.) in homepage specific area. – Md Amanullah Mar 3 '18 at 10:03
0

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!!

  • Yes, Working. Thankyou :) – Md Amanullah Mar 3 '18 at 11:54
  • @MdAmanullah Please mark it as accepted solution so others also can get benefits. – Padhiyar Gaurang Mar 5 '18 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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