Reza Saadati
Reza Saadati

Reputation: 1274

Ternary operator won't return HTML

I would like to use the ternary operator of Twig but it shows me the HTML tags as text.

{{ (sender.firstName or sender.lastName) ? "<strong>#{sender.firstName}  #{sender.lastName}</strong>" : '<strong>Unknown</strong>' }}

The result is <strong>My Name</strong> but it should be My Name.

Upvotes: 0

Views: 214

Answers (1)

DarkBee
DarkBee

Reputation: 15592

You have to apply the raw as the output is not marked as safe when concatenating html with twig

{{ (sender.firstName or sender.lastName ? "<strong>#{sender.firstName}  #{sender.lastName}</strong>" : "<strong>Unknown</strong>")|raw }}

demo

Upvotes: 1

Related Questions