Magento Email Template If Statements -
the magento email template if statements aren't evaluating true when expect them to. can tell me what's wrong? take @ 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 4, same result. how evaluate equalities magento email template if statements?
digging through code, looks template logic implemented varien_filter_template
(under lib\varien not app\code) in filter
function issues callback ifdirective
function if pattern matches regex. ifdirective
in turn uses _getvariable
function evaluate if
condition. _getvariable
tokenizes condition in varien_filter_template_tokenizer_variable
either property or method.
if($this->iswhitespace()) { // ignore white spaces continue; } else if($this->char()!='.' && $this->char()!='(') { // property or method name $parametername .= $this->char(); } else if($this->char()=='(') { // method declaration $methodargs = $this->getmethodargs(); $actions[] = array('type'=>'method', 'name'=>$parametername, 'args'=>$methodargs); $parametername = ''; } else if($parametername!='') { // property or variable declaration if($variableset) { $actions[] = array('type'=>'property', 'name'=>$parametername); } else { $variableset = true; $actions[] = array('type'=>'variable', 'name'=>$parametername); } $parametername = ''; }
when if condition detected method, execute method, otherwise returns string value of variable.
all of means (i think!) if want evaluate expression inside if statement, need add new customer attribute (there extensions available this) template can evaluate. if define boolean "ismemberofgroupnamex" attribute, template should work.
i imagine not answer you're looking for, i'm sure that's case.
hth, jd
Comments
Post a Comment