How to write “If string starts with” in Drupal 8 Twig templates
By Alvin Alexander. Last updated: July 30 2017
If you ever need to write a “string starts with” comparison in Drupal 8 Twig templates, I just used this approach in a node.html.twig template file and I can confirm that it works:
{% if uri starts with '/foo' %}
More accurately, what I did was to first get the URI for the current Drupal node, and then I perform that test: