- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hello,
I need to call a custom phtml from a cms page. I did create this:
/app/design/frontend/Hoop/Contact/contact.phtml
and this is cms page:
{{block name="hoopcontact" template="Hoop_Contact::contact.phtml"}}
but is not shown.
What am I doing wrong?
Thanks
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have to keep below routes.xml file code look like this,
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route id="hoopcontact" frontName="hoopcontact"> <module name="Hoop_Contact" /> </route> </router> </config>
You can't keep contact as frontName because contact is already used in Magento_Contact module.
You can keep hoop as frontName and access your url like,
http://<my_server>/hoopcontact/index/display
Clear cache and remove var folder and check.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: block core template cms page
@agiorgini, you have to keep contact.phtml in your module. Here you have keep your template file inside directly theme folder,
First you have to create your module folder like, Magento_Contact if your core file from contact module.
After Create Module folder you can keep your template file inside templates/contact.phtml file.
In your question, Hoop/Contact is a theme name,
If issue solved, click Kudos and Accept as Solution.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: block core template cms page
Hi Rakesh,
thanks for your answer. So I've created my Hoop/Contact module this is my /app/code/Hoop/Contact/etc/frontend/routes.xml:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route id="hoop" frontName="contact"> <module name="Hoop_Contact" /> </route> </router> </config>
while this is my /app/code/Hoop/Contact/Controller/Index/Display.php:
<?php namespace Hoop\Contact\Controller\Index; use Magento\Framework\Controller\ResultFactory; class Display extends \Magento\Framework\App\Action\Action { /** * @var \Magento\Framework\App\Cache\TypeListInterface */ protected $_cacheTypeList; /** * @var \Magento\Framework\App\Cache\StateInterface */ protected $_cacheState; /** * @var \Magento\Framework\App\Cache\Frontend\Pool */ protected $_cacheFrontendPool; /** * @var \Magento\Framework\View\Result\PageFactory */ protected $resultPageFactory; /** * @param Action\Context $context * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\Framework\App\Cache\StateInterface $cacheState * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\App\Cache\StateInterface $cacheState, \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { die('here'); parent::__construct($context); $this->_cacheTypeList = $cacheTypeList; $this->_cacheState = $cacheState; $this->_cacheFrontendPool = $cacheFrontendPool; $this->resultPageFactory = $resultPageFactory; } /** * Flush cache storage * */ public function execute() { $this->_view->loadLayout(); $this->_view->getLayout()->initMessages(); $this->_view->getPage()->getConfig()->getTitle()->set(__('Hoop Contact Frontend Title')); /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); return $resultPage; } }
then I try to browse: http://<my_server>/contact/index/display but I get 404. Where am I wrong here?
Many thanks
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have to keep below routes.xml file code look like this,
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route id="hoopcontact" frontName="hoopcontact"> <module name="Hoop_Contact" /> </route> </router> </config>
You can't keep contact as frontName because contact is already used in Magento_Contact module.
You can keep hoop as frontName and access your url like,
http://<my_server>/hoopcontact/index/display
Clear cache and remove var folder and check.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: block core template cms page
Hi,
I did but I still get 404 page... if I change frontName in routes.xml shouldn't I change it also somewhere else?
thanks
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: block core template cms page
ok this is definitely weird: I get no 404 error now, but a page where there is a label "Customer login", which I don't have anywhere in my code. Also, I did put a die as first instruction, in both constructor and execute() of my Display class, but it doesn't walk through there...
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: block core template cms page
have you installed module first?
Make sure module is active, you can check into app/etc/config.php
Module_Name => 1
If not then do setup upgrade then flush cache and check it.
Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer