How to add a variable in all Magento 2 templates?

In Magento 2 templates, we include a variable which is an easy way to insert a pre-defined part of code to your CMS pages or blocks. At this instant, we will establish to you how to add variable in all Magento 2 templates.

Variables are pieces of information that can build once and utilize in multiple places, such as Email templates, Blocks, and content pages. There are two types of variable:

  • Predefined variable
  • Custom variable

Your store holds a large number of predefined variable that can be used to individualize communication.

In Magento 2 you can discover default variables but the list of default variables is limited. In addition, you can make your own custom variables.

Now we will learn how to add variables in all Magento 2.3 templates.

Build your Amazon-like multi-vendor marketplace website @ $249/- now!!!
                Get your free live demo now: Click here

How to add a variable in all Magento 2 templates?

The following steps illustrate to you how to create predefined variables:

Step 1: Choose the template you want to include variables. It can be Email Templates or page templates.

For example: Go to marketing->communications->Email Templates. Then select a template you want to build a variable.

Step 2: select insert variables. Then select a variable that you want to create for that Magento 2 template.

Add a variable in all Magento 2 templates

Step 3: After completing, click save the template.

Steps illustrate to you how to create custom variables

Step 1: on the admin slide bar, tap system, then another setting ->custom variable.


After that select add new variable

Step 2: Enter the custom variable information

Add a variable in all Magento 2

  • In the variable field, enter an identifier and exploit all lowercase characters without space.
  • In variable name, type a variable name that is used as an internal reference
  • In the HTML value text field, form any content that you insert using HTML values. This option allows you to format the value.
  • Type the variable value as simple text in a variable plain value,

After complete, click save

Below-mentioned are some of the variable references which assist you to add a more custom variable in HTML.

Billing address: {{var formattedBillingAddress|raw}}
Email Order Note:  {{var order.getEmailCustomerNot1e()}}
Order ID: {{var order.increment_id}}
Order Item Grid:  {{layout handle=”sales_email_order_items”order=$order area=”frontend”}}
Payment Option:  {{var payment_html|raw}}
Shipping Address:  {{var formattedShippingAddress|raw}}
Shipping description: {{var order.getShippingDescription()}}

I hope the above-mentioned information will be useful for you to add variables in all Magento 2 templates.

Contact Webnexs for all your eCommerce developmental queries.

Add a variable in all Magento 2



, ,



Leave a Reply

Your email address will not be published. Required fields are marked *