Articles

Para saber qué plantilla genera el marcado para un elemento específico, puedes usar la opción integrada debug de Twig. Esta opción mostrará comentarios HTML junto con la salida renderizada, incluyendo los hooks de tema usados, los nombres sugeridos de archivos de plantilla, y señalará el archivo Twig exacto utilizado para renderizar una sección determinada de tu marcado.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

Los filtros en Twig pueden usarse para modificar variables. Los filtros se separan de la variable mediante el símbolo de barra vertical (pipe). Pueden tener argumentos opcionales entre paréntesis. Varios filtros pueden encadenarse. La salida de un filtro se aplica al siguiente.
Ejemplo:
{{ content|safe_join(", ")|lower }}
Puede que necesites renderizar un elemento antes de filtrarlo:

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

Twig proporciona una serie de funciones útiles que se pueden usar directamente en las plantillas.
El núcleo de Drupal añade varias funciones personalizadas específicas de Drupal. Estas están definidas en la clase TwigExtension.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

Desde la documentación oficial de Twig: «Los macros son comparables a las funciones en los lenguajes de programación tradicionales. Son útiles para colocar idioms HTML usados frecuentemente en elementos reutilizables, para evitar la repetición».

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

Para hacer que el theming en Drupal 8 sea lo más eficiente posible y proporcionar más opciones de personalización en las plantillas Twig, siga estas recomendaciones:

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

La idea general en Drupal 8 es que quieres evitar crear HTML directamente en el código PHP de tu módulo personalizado. Quieres que esto se maneje en las plantillas Twig. Para crear nuevas plantillas Twig en tu módulo, sigue estos pasos.
Paso 1: Define hook_theme en el archivo .module
Crea el archivo [módulo].module si aún no existe, y añade el código que define cada una de tus plantillas Twig. La clave de cada elemento en el array es lo que necesitarás para llamar a la plantilla más adelante. No uses guiones en el nombre del archivo.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

Las plantillas Twig pueden ser extendidas usando la siguiente sintaxis:
{% extends 'html.twig' %}
Para más detalles, consulte https://symfony.com/doc/current/templates.html#template-inheritance-and-layouts

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

Subtemas, como cualquier otro tema, se distinguen por una diferencia clave: heredan los recursos del tema padre. No existen restricciones en la cadena que conecta subtemas con sus padres. Un subtema puede ser hijo de otro subtema y puede estar organizado y ramificado como usted lo considere necesario.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.


Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

Documenta todos los selectores de clases CSS que existen en el tema Classy de Drupal 8 RC 2.
Formato:
.foo { }
.foo-bar { }
filename.html.twig / filename.css

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.