How can I use item metadata with `if` or `if_eq` helper in invoice email template

I’m trying to use the if_eq helper to change the display of item info based on the metadata associated with each item.
I know I can display the value of a metadata property using the displayJsonValue helper, for example {{ displayJsonValue this.metadata.some_info }} will output the value of some_flag, but I would like to make that output conditional. Something like:
`
{{ #if this.metadata.some_flag }}

{{ displayJsonValue this.metadata.some_info }}

{{ /eq }} ` Does anyone know how to do something like that?

Philippe

Hi @evlg, thanks for reaching out!

You can use a subexpression inside the if_eq to get a JSON value for comparison. Example:

    {{ #if_eq 'value1' (displayJsonValue order.metadata 'key')}}
      <span>order.metadata 'key' is {{ displayJsonValue order.metadata "key" }}</span>
    {{ else }}
      <span>order.metadata 'key' is not value1</span>
    {{ /if_eq }}

Is this what you’re looking for?

Thanks.

Yes, that’s exactly what I needed. Thanks.

1 Like