Magento2 | How to call Template from a Controller The Next CEO of Stack Overflowload magento controller method from TemplateHow to call a controller action from another module?How to call a model method from controller in Magento2Form Key Value in template and controllerMagento 2 - Got Error in Adminhtml Controller“Undefined property: Interceptor::$invoiceService” while overriding controller in magento2How to create Magento Order programatically in Amazon M2eproCall Controller from ButtonHow to override this block and template in my module?Magento 2.2.5: Overriding Admin Controller sales/order
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
Sending manuscript to multiple publishers
Why do professional authors make "consistency" mistakes? And how to avoid them?
Why am I allowed to create multiple unique pointers from a single object?
What's the best way to handle refactoring a big file?
Would a galaxy be visible from outside, but nearby?
Bold, vivid family
Rotate a column
Is it possible to search for a directory/file combination?
Are there any limitations on attacking while grappling?
What is the purpose of the Evocation wizard's Potent Cantrip feature?
How should I support this large drywall patch?
Why don't programming languages automatically manage the synchronous/asynchronous problem?
Non-deterministic sum of floats
Unreliable Magic - Is it worth it?
Interfacing a button to MCU (and PC) with 50m long cable
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
Novel about a guy who is possessed by the divine essence and the world ends?
Anatomically Correct Strange Women In Ponds Distributing Swords
Received an invoice from my ex-employer billing me for training; how to handle?
Elegant way to replace substring in a regex with optional groups in Python?
FBX seems to be empty when imported into Blender
Why has the US not been more assertive in confronting Russia in recent years?
At which OSI layer a user-generated data resides?
Magento2 | How to call Template from a Controller
The Next CEO of Stack Overflowload magento controller method from TemplateHow to call a controller action from another module?How to call a model method from controller in Magento2Form Key Value in template and controllerMagento 2 - Got Error in Adminhtml Controller“Undefined property: Interceptor::$invoiceService” while overriding controller in magento2How to create Magento Order programatically in Amazon M2eproCall Controller from ButtonHow to override this block and template in my module?Magento 2.2.5: Overriding Admin Controller sales/order
I got this controller:
<?php
namespace
clas extends MagentoSalesControllerAdminhtmlOrder
public function execute()
echo "TEST";
?>
I want it to call a template. How can I do that?
magento2 template controllers
add a comment |
I got this controller:
<?php
namespace
clas extends MagentoSalesControllerAdminhtmlOrder
public function execute()
echo "TEST";
?>
I want it to call a template. How can I do that?
magento2 template controllers
1
create handler on layout file and call phtml.
– Sukumar Gorai
Jul 3 '18 at 12:01
From a front-end dev - Please do not do it this way, calling a template from a PHP files makes life much more difficult if a FE dev ever wants to debug or make changes via layout XML.
– Ben Crook
Jul 3 '18 at 12:07
add a comment |
I got this controller:
<?php
namespace
clas extends MagentoSalesControllerAdminhtmlOrder
public function execute()
echo "TEST";
?>
I want it to call a template. How can I do that?
magento2 template controllers
I got this controller:
<?php
namespace
clas extends MagentoSalesControllerAdminhtmlOrder
public function execute()
echo "TEST";
?>
I want it to call a template. How can I do that?
magento2 template controllers
magento2 template controllers
edited 1 min ago
k33n
asked Jul 3 '18 at 11:51
k33nk33n
455110
455110
1
create handler on layout file and call phtml.
– Sukumar Gorai
Jul 3 '18 at 12:01
From a front-end dev - Please do not do it this way, calling a template from a PHP files makes life much more difficult if a FE dev ever wants to debug or make changes via layout XML.
– Ben Crook
Jul 3 '18 at 12:07
add a comment |
1
create handler on layout file and call phtml.
– Sukumar Gorai
Jul 3 '18 at 12:01
From a front-end dev - Please do not do it this way, calling a template from a PHP files makes life much more difficult if a FE dev ever wants to debug or make changes via layout XML.
– Ben Crook
Jul 3 '18 at 12:07
1
1
create handler on layout file and call phtml.
– Sukumar Gorai
Jul 3 '18 at 12:01
create handler on layout file and call phtml.
– Sukumar Gorai
Jul 3 '18 at 12:01
From a front-end dev - Please do not do it this way, calling a template from a PHP files makes life much more difficult if a FE dev ever wants to debug or make changes via layout XML.
– Ben Crook
Jul 3 '18 at 12:07
From a front-end dev - Please do not do it this way, calling a template from a PHP files makes life much more difficult if a FE dev ever wants to debug or make changes via layout XML.
– Ben Crook
Jul 3 '18 at 12:07
add a comment |
1 Answer
1
active
oldest
votes
check the below code
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $_resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
)
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
public function execute()
$resultPage = $this->_resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__(' heading '));
$block = $resultPage->getLayout()
->createBlock('CompanynameModuleBlockblockname')
->setTemplate('Companyname_Module::test.phtml')
->toHtml();
$this->getResponse()->setBody($block);
}
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f232177%2fmagento2-how-to-call-template-from-a-controller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
check the below code
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $_resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
)
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
public function execute()
$resultPage = $this->_resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__(' heading '));
$block = $resultPage->getLayout()
->createBlock('CompanynameModuleBlockblockname')
->setTemplate('Companyname_Module::test.phtml')
->toHtml();
$this->getResponse()->setBody($block);
}
add a comment |
check the below code
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $_resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
)
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
public function execute()
$resultPage = $this->_resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__(' heading '));
$block = $resultPage->getLayout()
->createBlock('CompanynameModuleBlockblockname')
->setTemplate('Companyname_Module::test.phtml')
->toHtml();
$this->getResponse()->setBody($block);
}
add a comment |
check the below code
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $_resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
)
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
public function execute()
$resultPage = $this->_resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__(' heading '));
$block = $resultPage->getLayout()
->createBlock('CompanynameModuleBlockblockname')
->setTemplate('Companyname_Module::test.phtml')
->toHtml();
$this->getResponse()->setBody($block);
}
check the below code
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $_resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
)
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
public function execute()
$resultPage = $this->_resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__(' heading '));
$block = $resultPage->getLayout()
->createBlock('CompanynameModuleBlockblockname')
->setTemplate('Companyname_Module::test.phtml')
->toHtml();
$this->getResponse()->setBody($block);
}
answered Jul 3 '18 at 12:07
Prashant PatelPrashant Patel
925315
925315
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f232177%2fmagento2-how-to-call-template-from-a-controller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
create handler on layout file and call phtml.
– Sukumar Gorai
Jul 3 '18 at 12:01
From a front-end dev - Please do not do it this way, calling a template from a PHP files makes life much more difficult if a FE dev ever wants to debug or make changes via layout XML.
– Ben Crook
Jul 3 '18 at 12:07