简体   繁体   中英

Show variable within TWIG short form if/else statement with HTML

{{r.status == 'active' or 'scheduled' ? 'The order status is <a href="https://example.com/"> 
{{r.order}} : 'The order status is cancelled'</a>'

When using the line above it prints {{r.order}} instead of the value from the variable. How can I print the value?

You may use the in operator combined with string interpolation and the raw filter :

{{r.status in ['active', 'scheduled'] 
  ? "The order status is <a href=\"https://example.com/\">#{r.order}</a>"|raw 
  : 'The order status is cancelled'}}

Demo: https://twigfiddle.com/tj2skl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM