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 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.

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

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.

Step 3: After completing, click save the template.

The following 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

  • 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.

Last Update: February 4, 2021  

February 2, 2018   3915   Nandini Ramachandran    Magento, Magento 2 Tutorial, Magento 2.3    
Total 2 Votes:
1

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 *

Facebook
Twitter
INSTAGRAM
LinkedIn