A malformed Twig template can break a page only when a particular component is rendered. A dedicated syntax check catches template problems during CI before they reach an environment.
twig-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.13"
- run: python -m pip install djlint==1.44.2
- name: Report Twig syntax findings
continue-on-error: true
run: |
find docroot/modules/custom docroot/themes/custom \
-type f -name '*.html.twig' -print0 \
| xargs -0 -r djlint --profile=nunjucks --lint
-print0 and xargs -0 safely handle unusual file names. -r avoids invoking djLint when no templates exist. Searching only custom directories keeps findings actionable and avoids reporting contributed code.
The Nunjucks profile is close to Twig, but it does not understand every Drupal-specific function or filter. Verify unexpected findings instead of blindly rewriting valid Drupal markup.
This check is initially reporting-only. Syntax linting also cannot prove that a Drupal variable exists, that output is accessible, or that a component looks correct. Pair it with Drupal coding standards, automated tests, and accessibility review.