Template : how to get first character of the title?

by Tritof   Last Updated September 14, 2018 15:07 PM

The ultimate goal is to be able, in the node--my-content-type.html.twig, to use this title in a statement using an article in french, language in which the article depends on the first letter of a word:

  • Banane => de Banane;
  • Orange => d'Orange;

So based on Twig documentation, I'm trying to use:

  • {% if label|first|lower == o %}
    OR
  • {% if label|slice(0, 1)|lower == o %}
    OR
  • {% if label[:1]|lower == o %}

But none of it worked so far.

Tags : 8 theming


Related Questions


Features can export everything?

Updated March 26, 2015 10:02 AM


No image style found

Updated March 29, 2015 15:02 PM


Best way to have 5 or 6 themes in one site drupal 7

Updated April 09, 2015 22:03 PM