Magento Email Template If Statements

John picture John · Jan 25, 2011 · Viewed 30.8k times · Source

The Magento Email Template If Statements aren't evaluating to true when I expect them to. Can someone tell me what's wrong? Take a look at the following code:

{{var customer.group_id}}
{{if customer.group_id}}Print true{{else}}Print false{{/if}}
{{if customer.group_id==4}}Print true{{else}}Print false{{/if}}
{{if customer.group_id=4}}Print true{{else}}Print false{{/if}}
{{if customer.group_id eq 4}}Print true{{else}}Print false{{/if}}

The output is

4
Print True
Print False
Print False
Print False

I tried putting quotes around the 4, but same result. How do I evaluate equalities with magento email template if statements?

Answer

ʍǝɥʇɐɯ picture ʍǝɥʇɐɯ · Jul 8, 2011

I solved this problem by using the 'block' technique.

What you do is you pass the order to a block and then do your logic inside that block.

Although my solution is for a different problem the approach should work here.

What I wanted was to have a pay by cheque option and some extra text in the confirmation email reminding them to pay. I added this into the new order template:

{{block type='core/template' area='frontend' template='paymentstatus/orderemail.phtml' order=$order}}<br />

Then I created a file app/design/frontend/default/default/template/paymentstatus/orderemail.phtml

This has the 'if' logic, in my case I wanted to see if the order status was that for a cheque and only then remind the customer that their order needed cleared funds.

<?php if($this->getData('order')->getStatus()=='cheque') {
echo "<p>Please note that we will require your cheque to clear before we can despatch your order.</p>"; }?>