1

I want to check for null values in Scriban.

{{ if (o_model.address.id) }}
<div  style="text-align: center;"><h5>Address {{ o_model.address.id}}</h5><br /></div>
{{ end }}

I am getting this error

error : Object `o_model.address` is null. Cannot access member: o_model.address.id

What I am doing wrong here?

5
  • 3
    Have you tried something like if (o_model.address && o_model.address.id)?
    – Marek Musielak
    Commented Aug 7, 2020 at 7:30
  • Not sure what part of Object o_model.address is null is unclear
    – Mark Cassidy
    Commented Aug 7, 2020 at 11:37
  • @MarkCassidy thanks it works
    – user2980
    Commented Aug 10, 2020 at 2:49
  • @MarkCassidy Marek solutions works thanks
    – user2980
    Commented Aug 10, 2020 at 2:49
  • See github.com/scriban/scriban/issues/191 Commented Mar 5, 2021 at 3:14

1 Answer 1

2

This works

{{ if (o_model.address)}}
    {{ if (o_model.address.id)}}
    {{ end }} 
{{ end }}

Thanks Marek

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.