How to add variable in all magento 2 templates?-Magento 2.3

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 you how to add variable in all Magento 2 templates.

Variables are piece 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 large number of a predefined variable that can be used to individualize communication.

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

Now we will learn how to add variable in all magento templates.

Looking for Magento 2.3 development guidance regarding selecting the right developer? Click here Get your Free Consultation 

The following steps illustrate 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 variables that you want to create to that template.

Step 3: After completing, click save template.

The following steps illustrate you how to create custom variables:

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


After that select add new variable

Step 2: Enter the custom variable information

  • In variable field, enter an identifier and exploit all lowercase character without space.
  • In variable name, type a variable name which is used as an internal reference
  • In 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

The below mentioned are some of the variable reference which assists you to add 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 you to add variable in all magento templates.

Last Update: September 15, 2020  

February 2, 2018   3449   Nandini Ramachandran    Marketing    
Total 2 Votes:

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

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