25

we are investigating some checks in our transactional emails or newsletters and looking at http://merch.docs.magento.com/ce/user_guide/store-operations/email-transactional.html

where we find the code below.

My question: can we use this DEPEND or IF to check the existence or emptiness of a variable? Something like

{{if customer.getFirstname()}} 
  {{var customer.firstname}} 
{{else} 
  {{var customer.name}} 
{{/if}}

Example from link

Depend Condition

{{depend order.getIsNotVirtual()}}

{{/depend}}

{{depend salable}}

{{/depend}}

- If Condition

{{if order.getIsNotVirtual()}}

{{else}}

{{/if}}

(else is optional)

1 Answer 1

45

This is exactly the purpose of {{depend}} and {{if}}. The only difference between them is that {{if}} supports an {{else}} statement.
{{depend}} is just as an {{if}} without an {{else}}.
To see how they work refer to Varien_Filter_Template::dependDirective() and Varien_Filter_Template::ifDirective().

6
  • 2
    and if I want to compare with a string like {{order.getStatus() == 'pending_payment'}} ? Commented Jul 24, 2018 at 19:49
  • @DiegoQueiroz Did you find your answer?
    – snh_nl
    Commented Jan 18, 2019 at 15:40
  • @snh_nl Yes! I Found! Commented Jan 24, 2019 at 16:00
  • 1
    Can you share the link?
    – snh_nl
    Commented Jan 24, 2019 at 17:38
  • 1
    To the people asking the link from Diego, it's not possible to use ==. Here you can find an alternative and more information -> magento.stackexchange.com/questions/161041/…
    – Sanne
    Commented Apr 25, 2019 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.