How can I get the first character of the node title? In the node--my-content-type.html.twig, I want to add the French indefinite article to the title, which depends on the first letter of the word to which the article is added.  


Banane => de Banane
Orange => d'Orange


So based on the Twig documentation, I'm trying to use one of the following code lines.

{% if label|first|lower == o %} 




{% if label|slice(0, 1)|lower == o %}




{% if label[:1]|lower == o %}


None of them work.

How can I get the first character of the node title?
You could try this code:  

/**
 * Implements hook_preprocess_HOOK().
 * @param $variables array
 */
function TEMPLATE_preprocess_node(&amp;$variables)
{
  /** @var \Drupal\node\Entity\Node $node */
  $node = $variables['node'];
  $title = $node-&gt;getTitle();
  if(_isFirstCharIsVowel($title)){
    $variables['title_addition'] = "D'";
  }else {
    $variables['title_addition'] = "De ";
  }
}

/**
 * Check if the first character is a vowel
 * @param $string string
 * @return bool
 */
function _isFirstCharIsVowel($string){
  $vowels =
    'aàáâãāăȧäảåǎȁąạḁẚầấẫẩằắẵẳǡǟǻậặæǽǣ' .
    'AÀÁÂÃĀĂȦÄẢÅǍȀȂĄẠḀẦẤẪẨẰẮẴẲǠǞǺẬẶÆǼǢ' .
    'EÈÉÊẼĒĔĖËẺĚȄȆẸȨĘḘḚỀẾỄỂḔḖỆḜ' .
    'eèéêẽēĕėëẻěȅȇẹȩęḙḛềếễểḕḗệḝ' .
    'IÌÍÎĨĪĬİÏỈǏỊĮȈȊḬḮ' .
    'iìíîĩīĭıïỉǐịįȉȋḭḯ' .
    'OÒÓÔÕŌŎȮÖỎŐǑȌȎƠǪỌØỒỐỖỔȰȪȬṌṐṒỜỚỠỞỢǬỘǾŒ' .
    'oòóôõōŏȯöỏőǒȍȏơǫọøồốỗổȱȫȭṍṏṑṓờớỡởợǭộǿœ' .
    'UÙÚÛŨŪŬÜỦŮŰǓȔȖƯỤṲŲṶṴṸṺǛǗǕǙỪỨỮỬỰ' .
    'uùúûũūŭüủůűǔȕȗưụṳųṷṵṹṻǖǜǘǖǚừứữửự'
  ;
  // set necessary encodings
  mb_internal_encoding('UTF-8');
  mb_regex_encoding('UTF-8');
  $first = mb_substr($string, 0, 1);
  $vow = mb_ereg_replace('[^'.$vowels.']','',  $first);
  return !empty($vow);
}


This can be used in your .theme or .module file.
This of course will act on all nodes, so you need to add your type checking.
The _isFirstCharIsVowel function can be in a service, I placed it here for simplicity



UPDATE
Credits for vowwl detectioon goes to this https://stackoverflow.com/questions/14268970/how-to-detect-and-echo-the-last-vowel-in-a-word