I use Timber plugin for Wordpress.
And I create a results search page. I would like to highlight the word that the user searched.
In PHP I wrote that :
$highlight = array();
if ($terms) {
foreach($terms as $term) {
array_push($highlight, '<span class="blue bold">'.$term.'</span>');
}
}
And that, to replace the searched word in PHP :
<p class="date red"><?php echo str_ireplace($terms, $highlight, get_field('subtitle_post')); ?></p
But I don't know how to transform that in Twig (Timber) ?
You should use a custom twig filter.
From the documentation: extending timber. (I tried to adapt it to your example but you might need to change it)
Then you could use your custom filter with