Thémer drupal 8

Twig (base)

La base : https://sqndr.github.io/d8-theming-guide/twig/twig-basics.html

Twig est en "autoescape" = Tout ce qui est entre {{ }} est en "esc".

Pour "afficher" une variable dans un template: {{ variable }}
on a accès à ses attributs après un point ; ex:

{{ awesome_array.a_key }} # returns 'a_value'
{{ awesome_array.another_key.foo }} # returns 'bar'

Les filtres

On peux faire en sorte que variable utilise un filter avant de l'afficher: {{ variable|filter }}.

https://twig.symfony.com/doc/2.x/filters/index.html

Drupal ajoute des filtres supplémentaires : Translation, safe_join, Array...

Translation -> t()

Array: without

Commentaires : {# Comments go inside these brackets. #}

Fontion si :

{% if site_slogan %}
  <div class="site-slogan">{{ site_slogan }}</div>
{% endif %}

 

Twig (moyen)

https://sqndr.github.io/d8-theming-guide/custom-theme/index.html

 

plus sur le web

logo drush