I would like to generate a link like this:

<a href="http://example.com/my-custom-page">My link</a>

Target page: example.com/my-custom-page.

Template: module-customer/view/frontend/templates/form/register.phtml

  • U need to use custom Router.php or make Controller file will needed path
    – Jackson
    Commented Oct 4, 2016 at 1:48

3 Answers 3


First, use cms page to create new page with identifier is your_custom_page_link.

In your phtml file, use this code: <a href="<?php echo $this->getUrl('your_custom_page_link') ?>">Link label</a>


First you need to add dependency in your related block

    public $_storeManager;
    public function __construct(
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    ) {
    public function getCustomUrl($customUrl){
      return $this->_storeManager->getStore()->getBaseUrl() . $customUrl;

Add in your template below code:

echo $block->getCustomUrl('my-custom-page');
  • hi ,@Prashant, how can i pass argument to template file without appending it tot the Browser Url Commented Jan 28, 2019 at 11:39

get url key of your page : enter image description here

and put it in your href

<a href="url_key_of_your_page"></a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.