Magento2 | How to call Template from a Controllerload 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 ButtonMagento 2.2.5: Overriding Admin Controller sales/orderMagento2: How can call observer function in controller file?
My employer is refusing to give me the pay that was advertised after an internal job move
Rampant sharing of authorship among colleagues in the name of "collaboration". Is not taking part in it a death knell for a future in academia?
Unknown indication below upper stave
Security measures that could plausibly last 150+ years?
How to choose using Collection<Id> rather than Collection<String>, or the opposite?
How can Paypal know my card is being used in another account?
Avoiding Implicit Conversion in Constructor. Explicit keyword doesn't help here
How to foreshadow to avoid a 'deus ex machina'-construction
What force enables us to walk? Friction or normal reaction?
Are all French verb conjugation tenses and moods practical and efficient?
Is it possible for a particle to decay via gravity?
Correct word for a little toy that always stands up?
What is the highest achievable score in Catan
Can you continue the movement of a Bonus Action Dash granted by Expeditious Retreat if your Concentration is broken mid-move?
What are the cons of stateless password generators?
Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?
Why did some Apollo missions carry a grenade launcher?
Why are subdominants unstable?
Boots or trail runners with reference to blisters?
What is my clock telling me to do?
Is Ear Protection Necessary For General Aviation Airplanes?
How to innovate in OR
Why does the Rust compiler not optimize code assuming that two mutable references cannot alias?
Scam? Checks via Email
Magento2 | How to call Template from a Controller
load 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 ButtonMagento 2.2.5: Overriding Admin Controller sales/orderMagento2: How can call observer function in controller file?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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 Mar 29 at 22:15
k33n
asked Jul 3 '18 at 11:51
k33nk33n
4551 silver badge16 bronze badges
4551 silver badge16 bronze badges
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 |
2 Answers
2
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 |
In controller:
use MagentoFrameworkAppActionAction;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppActionContext;
use OXOfferNotifierHelperData;
class Index extends Action
protected $_resultPageFactory;
protected $_resultJsonFactory;
protected $_helperData;
public function __construct(Context $context, PageFactory $resultPageFactory, JsonFactory $resultJsonFactory, Data $data)
parent::__construct($context);
$this->_resultPageFactory = $resultPageFactory;
$this->_resultJsonFactory = $resultJsonFactory;
$this->_helperData = $data;
public function execute()
if ($this->_helperData->isOfferNotifierEnabled())
$result = $this->_resultJsonFactory->create();
$resultPage = $this->_resultPageFactory->create();
$productId = $this->getRequest()->getParam("productId");
$offerInProductView = $this->getRequest()->getParam("offerInProductView") ?? 0;
$url = $this->getRequest()->getParam("url") ?? 0;
//Get the product id for ProductView Page
if ($offerInProductView)
$productInfo = $resultPage->getLayout()
->createBlock('OOOYYYBlockProductView')
->setData('product_id', $productId)
->setData('offer_in_product_view', $offerInProductView)
->setTemplate('OOO_YYY::product/view/offer-notifier.phtml')
->toHtml();
$result->setData(['content' => $productInfo]);
return $result;
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
2 Answers
2
active
oldest
votes
2 Answers
2
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
9513 silver badges15 bronze badges
9513 silver badges15 bronze badges
add a comment |
add a comment |
In controller:
use MagentoFrameworkAppActionAction;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppActionContext;
use OXOfferNotifierHelperData;
class Index extends Action
protected $_resultPageFactory;
protected $_resultJsonFactory;
protected $_helperData;
public function __construct(Context $context, PageFactory $resultPageFactory, JsonFactory $resultJsonFactory, Data $data)
parent::__construct($context);
$this->_resultPageFactory = $resultPageFactory;
$this->_resultJsonFactory = $resultJsonFactory;
$this->_helperData = $data;
public function execute()
if ($this->_helperData->isOfferNotifierEnabled())
$result = $this->_resultJsonFactory->create();
$resultPage = $this->_resultPageFactory->create();
$productId = $this->getRequest()->getParam("productId");
$offerInProductView = $this->getRequest()->getParam("offerInProductView") ?? 0;
$url = $this->getRequest()->getParam("url") ?? 0;
//Get the product id for ProductView Page
if ($offerInProductView)
$productInfo = $resultPage->getLayout()
->createBlock('OOOYYYBlockProductView')
->setData('product_id', $productId)
->setData('offer_in_product_view', $offerInProductView)
->setTemplate('OOO_YYY::product/view/offer-notifier.phtml')
->toHtml();
$result->setData(['content' => $productInfo]);
return $result;
add a comment |
In controller:
use MagentoFrameworkAppActionAction;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppActionContext;
use OXOfferNotifierHelperData;
class Index extends Action
protected $_resultPageFactory;
protected $_resultJsonFactory;
protected $_helperData;
public function __construct(Context $context, PageFactory $resultPageFactory, JsonFactory $resultJsonFactory, Data $data)
parent::__construct($context);
$this->_resultPageFactory = $resultPageFactory;
$this->_resultJsonFactory = $resultJsonFactory;
$this->_helperData = $data;
public function execute()
if ($this->_helperData->isOfferNotifierEnabled())
$result = $this->_resultJsonFactory->create();
$resultPage = $this->_resultPageFactory->create();
$productId = $this->getRequest()->getParam("productId");
$offerInProductView = $this->getRequest()->getParam("offerInProductView") ?? 0;
$url = $this->getRequest()->getParam("url") ?? 0;
//Get the product id for ProductView Page
if ($offerInProductView)
$productInfo = $resultPage->getLayout()
->createBlock('OOOYYYBlockProductView')
->setData('product_id', $productId)
->setData('offer_in_product_view', $offerInProductView)
->setTemplate('OOO_YYY::product/view/offer-notifier.phtml')
->toHtml();
$result->setData(['content' => $productInfo]);
return $result;
add a comment |
In controller:
use MagentoFrameworkAppActionAction;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppActionContext;
use OXOfferNotifierHelperData;
class Index extends Action
protected $_resultPageFactory;
protected $_resultJsonFactory;
protected $_helperData;
public function __construct(Context $context, PageFactory $resultPageFactory, JsonFactory $resultJsonFactory, Data $data)
parent::__construct($context);
$this->_resultPageFactory = $resultPageFactory;
$this->_resultJsonFactory = $resultJsonFactory;
$this->_helperData = $data;
public function execute()
if ($this->_helperData->isOfferNotifierEnabled())
$result = $this->_resultJsonFactory->create();
$resultPage = $this->_resultPageFactory->create();
$productId = $this->getRequest()->getParam("productId");
$offerInProductView = $this->getRequest()->getParam("offerInProductView") ?? 0;
$url = $this->getRequest()->getParam("url") ?? 0;
//Get the product id for ProductView Page
if ($offerInProductView)
$productInfo = $resultPage->getLayout()
->createBlock('OOOYYYBlockProductView')
->setData('product_id', $productId)
->setData('offer_in_product_view', $offerInProductView)
->setTemplate('OOO_YYY::product/view/offer-notifier.phtml')
->toHtml();
$result->setData(['content' => $productInfo]);
return $result;
In controller:
use MagentoFrameworkAppActionAction;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppActionContext;
use OXOfferNotifierHelperData;
class Index extends Action
protected $_resultPageFactory;
protected $_resultJsonFactory;
protected $_helperData;
public function __construct(Context $context, PageFactory $resultPageFactory, JsonFactory $resultJsonFactory, Data $data)
parent::__construct($context);
$this->_resultPageFactory = $resultPageFactory;
$this->_resultJsonFactory = $resultJsonFactory;
$this->_helperData = $data;
public function execute()
if ($this->_helperData->isOfferNotifierEnabled())
$result = $this->_resultJsonFactory->create();
$resultPage = $this->_resultPageFactory->create();
$productId = $this->getRequest()->getParam("productId");
$offerInProductView = $this->getRequest()->getParam("offerInProductView") ?? 0;
$url = $this->getRequest()->getParam("url") ?? 0;
//Get the product id for ProductView Page
if ($offerInProductView)
$productInfo = $resultPage->getLayout()
->createBlock('OOOYYYBlockProductView')
->setData('product_id', $productId)
->setData('offer_in_product_view', $offerInProductView)
->setTemplate('OOO_YYY::product/view/offer-notifier.phtml')
->toHtml();
$result->setData(['content' => $productInfo]);
return $result;
answered Jul 21 at 14:38
Mano MMano M
1,1804 silver badges25 bronze badges
1,1804 silver badges25 bronze badges
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