I have a static block in Magento with this content:
<li><a href="#/contacts">Contact Us</a></li>
I would like to replace the # with the site's base url. I want it to retrieve this dynamically.
Step-1: Create a page through CMS>Pages. In 'Page Information' Tab section we set URL Key* page-contact-us Necessary Text can be written through the content tab area. That's all, the Base URL of that Static-block is now activated and can be retrieved dynamically.
If you need to get current URL in Magento 2 PHTML file the easiest way to do this is to use the following code: $currentUrl = $block->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]); This is the best method since you don't even need to use the Object Manager.
Base URL — http://www.yourdomain.com/magento/ Secure Base URL — https://www.yourdomain.com/magento/
Try adding this to your static block:
<a href="{{store url=""}}">Link to Base URL</a>
That should create a link to your store's base URL.
you can use this {{store direct_url="contacts"}}
For example:
<a href="{{store direct_url="contacts"}}">contact us</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With