1

I want to use || in {{if}}

I tryed like this but it not work, please help me

{{if helper.eq(order.shipping_description, "abcd") || helper.eq(order.shipping_description, "dede") }}
<p>abcd & dede</p>
{{else}}
<p>Not abcd & dede</p>
{{/if}}

It only work with helper.eq(order.shipping_description, "abcd"), not work with helper.eq(order.shipping_description, "dede")

0

I may be wrong on this, but I don't think the {{if}} directive works with conditions like varName == "varValue".
I wasn't able to find int he core any use like this.
I think it only works with

{{if varName}}
    text shown when varName evaluates to true
{{else}}
    text shown when varName evaluates to false
{{/if}}   

You can check how everything works, but debugging the method \Magento\Framework\Filter\Template::ifDirective.

But I may have a solution for your problem.
I assume the helper variable is something custom that you can control.
You can get rid of the if directive, but doing the checks in your helper class.

Here is an example:

public function getShippingDescriptionMessage($order)
{
    $description = $order->getShippingDescription();
    if ($description === 'abcd' || $description === 'dede') {
        return __('abcd & dede');
    }
    return __('Not abcd & dede');
}

then replace your whole {{if}}{{else}}{{/if}} directive with

{{var helper.getShippingDescriptionMessage($order)}}

Note: Haven't tested this. But it looks like it may work

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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