I'm new to Magento
I get this template that I don't want to split into multiple blocks. I just want to render the page as it is (not only, but this is something I can try to understand later) when I go to some url.
So for example, going to /route/controller/action
should display an html page I wrote from <HTML>
to </HTML>
(including, of course, HEAD and BODY).
So I read a few things. I followed some official tutorials and could create a module and an Action to render a JSON. Works fine! Going to /test/page/view shows a dumb json. Now I want to do something similar to render a page (and eventually pass parameters to it)
(http://devdocs.magento.com/videos/fundamentals/create-a-new-module/)
So this is what I get right now:
/Vendor/Module/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="victor" frontName="test">
<module name="Victor_Template" />
</route>
</router>
</config>
/Vendor/Module/Controller/Page/View.php
namespace Victor\Template\Controller\Page;
use \Magento\Backend\App\Action\Context;
use \Magento\Framework\App\Action\Action;
use \Magento\Framework\Controller\Result\JsonFactory;
use \Magento\Framework\View\Result\PageFactory;
class View extends Action
{
protected $resultPageFactory;
function __construct(Context $context, PageFactory $resultPageFactory){
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute(){
return $this->resultPageFactory->create();
}
}
.../view/frontend/layout/template_page_view.xml (maybe the error is here)
<?xml version="1.0" ?>
<page layout="1column" 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="Victor\Template\Block\Page\View" name="page.view" template="Victor_Template::page/view.phtml"/>
</referenceContainer>
</body>
</page>
.../view/frontend/templates/page/view.phtml
<h1>Hello World!</h1>
After cleaning cache, flushing cache, giving permissions and upgrading setup (something I have to do all the time some change occurs in the code), I get an HTTP code 200 that gives me back a blank (totally white) Magento page that contains references to css, javascript files and a weird like this:
<body data-container="body" data-mage-init='{"loaderAjax": {}, "loader": { "icon": "http://localhost/magento/pub/static/version1490812084/frontend/Magento/luma/en_US/images/loader-2.gif"}}' class="victor-page-view page-layout-admin-1column">
Anyway, I don't know what is happening in background. Something tells me the error is the definition of the layout (template_page_view
)
I wanted the response to be just <h1>Hello World!</h1>
.
What am I doing wrong and what is the proper way of doing it on Magento??
@edit
I added this to my View:
$resultPage = $this->resultPageFactory->create();
$resultPage->addHandle('template_page_view'); //loads the layout of module_custom_customlayout.xml file with its name
return $resultPage;
And now I get this error:
Object DOMDocument should be created.#0 /.../magento/vendor/magento/framework/View/Element/UiComponent/Config/Reader.php(95): Magento\Framework\View\Element\UiComponent\Config\DomMerger->getDom()
Is it a permission issue? Did I setup my layout incorrectly?
Regarding the layout, I took it from a tutorial I saw in a random website, what does the class
property refering to /Block
mean?