The email template system in Orocommerce came with various techniques to make it dynamic and more readable to last email recipient .
1 – Variables:
Often the variables is related to entities , for example if you have chosen order entity related to your template you will have the id , creation date , baseTotalValue …. and you will have access to variables of related entities too , like entity billingAddress , customer ….
So you can use directly inside you editor and the system going to render the real value based on current entity (order id or quote id)
example :
Please see your order #{{ entity.identifier }} details below.
{{ entity.identifier }} : I wanna render here the identifier of current order which used on this email , the result is Order #FR1012401 .
2 – Filters:
The filters is a function but with specific usage (object to string , formating or other) , for example filter date to string or render object price to string price with currency .
Emails have independent twig renderer with the sandbox to disable all not required twig filters or functions.
Some allowed filters is:
'oro_format_address', 'oro_format_date', 'oro_format_time', 'oro_format_datetime', 'oro_format_datetime_organization', 'oro_format_name', 'date', 'oro_format_currency', 'oro_html_sanitize'
like default twig filter are applied to Twig variables by using the | character followed by the filter name
Example:
Order Date: {{ entity.createdAt|oro_format_date }}
{{ entity.createdAt|oro_format_date }} : get my object date createdAt and convert to string with specific format , the result is Order Date: Feb 6, 2019 .
3 – Functions :
Often we’re using function to get complex data to use as simple array collection or final string render,
like Twig functions are called directly with any parameters being passed in via parenthesis.
Example:
{% set data = order_line_items(entity) %} : the function order_line_items take in parameter our current order entity and we have used -{% set- to affect to result in variables data , this variable data can give us many sub data :
{% for item in data.lineItems %} : data.lineItems return collection of all items related to current order
{{ data.total.totalPrice|oro_format_price }} : the variable data return too the total price of order we have used filter oro_format_price to formatting it to to specific format , our result $47,494.53
Some allowed function:
'oro_order_shipping_method_label', 'get_payment_methods', 'get_payment_status_label', 'get_payment_status', 'line_items_discounts', 'get_payment_status', 'get_payment_status_label', 'get_payment_term', 'get_payment_method_label', 'oro_payment_method_config_template', 'getlabel'
this just some lines for general usage …...
Comments