Skip to content
NewRedesigned blogFeedback
Jigar Karangiya

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

Instead of passing hardcoded values, we can dynamically get these values and pass them to the XML using {{baseUrl}} variable.

Magento 2: How to get a dynamic Base URL Path in XML?
Written by
JKJigar Karangiya
Published
Reading time
1 min read

Jigar Karangiya · · 1 min read

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 :

/app/code/Jigar/MyAccountBreadCrumbs/view/frontend/layout/customer_account.xml

xml
<?xml version="1.0"?>
<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="breadcrumbs">
            <action method="addCrumb">
                <argument name="crumbName" xsi:type="string">home</argument>
                <argument name="crumbInfo" xsi:type="array">
                    <item name="title" xsi:type="string">Home</item>
                    <item name="label" xsi:type="string">Home</item>
                    <item name="link" xsi:type="string">{{baseUrl}}</item>
                </argument>
            </action>
            <action method="addCrumb">
                <argument name="crumbName" xsi:type="string">my-account</argument>
                <argument name="crumbInfo" xsi:type="array">
                    <item name="title" xsi:type="string">My Account</item>
                    <item name="label" xsi:type="string">My Account</item>
                    <item name="link" xsi:type="string">{{baseUrl}}customer/account</item>
                </argument>
            </action>
        </referenceBlock>
    </body>
</page>

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 : https://example.com/first_store_view/ (opens in new tab)

for My Account : https://example.com/first_store_view/customer/account (opens in new tab)

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

Thanks, Keep Supporting !!

Keep reading
All posts

01 · 10 min · Shares Adobe Commerce Core

Adobe Commerce Agentic Capabilities, Q4 2026

Five agentic releases for Adobe Commerce: LLM product discovery, Brand Visibility, the Shopper MCP server, Brand Concierge, and Experience Workspace. What each one does, which editions get it, and when.

10 min

03 · 3 min · Shares Adobe Commerce Core

Conditions for Collections in Magento 2

Collections in Magento 2 (Now Adobe Commerce), are among the most powerful tools for retrieving and manipulating data directly from the database.

3 min

Newsletter

New Magento tutorials, straight to your inbox

Code examples, performance tips, and fixes for common Magento issues. No spam.

Subscribe