How to get a page url from a *.phtml template in Magento 2?
To get a page url from a *.phtml template in Magento 2, you can call the
1 2 3 4 |
public function getUrl($route = '', $params = []) { return $this->_urlBuilder->getUrl($route, $params); } |
1 |
$block->getUrl(); |
or
1 |
$block->getUrl('adminhtml/notification/index'); |
The core example looks as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
* See COPYING.txt for license details. */ ?> <p><?php /* @escapeNotVerified */ echo __('You have signed out and will go to our homepage in 5 seconds.') ?></p> <script> require([ "jquery", "mage/mage" ], function($){ $($.mage.redirect("<?php /* @escapeNotVerified */ echo $block->getUrl() ?>", "assign", 5000)); }); </script> |