In Magento 2, We can set page title using Controller as well as Using XML. I have given example for set page title using Controller and XML Way.
Using Controller,
1 2 3 4 5 6 | public function execute() { $this->_view->loadLayout(); $title = __('Page Title'); $this->_view->getPage()->getConfig()->getTitle()->prepend($title); $this->_view->renderLayout(); } |
Using Controller, We can set title by just call lineĀ $this->_view->getPage()->getConfig()->getTitle()->prepend(‘title name’)
Using XML,
1 2 3 | <head> <title>title name of page</title> </head> |
Using XML you can set your page title by <title> tag in <head> section.