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>
<p>Not abcd & dede</p>

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


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
    text shown when varName evaluates to false

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

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.