Magento 2: How to get a dynamic Base URL Path in XML?

Hello Magento Devs,

In today’s tutorial, we are going to see how we can get the Base URL path dynamically in any XML File.

In some cases, you are required to get the Base URL and pass it into the XML file.

Instead of passing hardcoded values, we can dynamically get these values and pass them to the XML.

Suppose, You are adding custom breadcrumbs to your account section and you are required to pass the base URL to generate the URL.

You can get a dynamic Base URL using {{baseUrl}} variable in XML.

Let’s consider below example :


As shown in the above example, I have prepared the breadcrumbs URL by adding dynamic {{baseUrl}}.

So it will generate the below URL accordingly.

for Home:

for My Account:

That’s it for today’s tutorial, See you in the next blog.

Thanks, Keep Supporting !!