How to add variable in all magento 2 templates

In Magento 2 templates, we have a variable which is a simple way to insert a pre-defined part of code to your CMS pages or Blocks. Now, we will introduce you how to add variable in all Magento 2 templates.

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

  • Predefined variable
  • Custom variable

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

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

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

The following steps show you how to create predefined variables:

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

For example: navigate to marketing->communications->Email Templates. Then choose a template you want to create a variable.

Step 2: select insert variables. Then choose a variables that you want to create to that template.

Step 3: After completing, click save template.

The following steps show 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 utilize all lowercase character without space.
  • In variable name, enter a variable name which is used as an internal reference
  • In HTML value text field, type any content that you add using HTML values. This option permits you to format the value.
  • Type the variable value as plain text in a variable plain value,

After complete, click save

The following are some of the variable reference which helps 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 this information will be useful you to add variable in all magento templates.

Last Update: July 18, 2018  

February 2, 2018   351   Nandini R    Marketing    
Total 1 Votes:
0

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
Google+
http://www.webnexs.com/blog/kb/add-variable-magento-2-templates
Twitter
LinkedIn