Craft CMS 5 Twig Guidelines

•
52
•

Standardizes Twig template development in Craft CMS 5 through consistent naming conventions, modern syntax, and optimized tag usage.

This skill provides a comprehensive set of coding standards and best practices for Craft CMS 5 Twig templates, ensuring production-ready code quality and maintainability. It enforces camelCase variable naming, safe null handling with the nullsafe operator, and strict component isolation using 'only' includes. By leveraging specialized Craft 5.10+ helpers like the {% tag %} function and the chainable collect() API, it helps developers build accessible, performant frontend components while avoiding common pitfalls like UI macros and ambient variable leaks.

Características Principales

0152 GitHub stars
02Optimized use of Craft Twig helpers including {% tag %}, attr(), and the svg() function.
03Standardized camelCase variable naming and no-abbreviation policy for template clarity.
04Strict component isolation using mandatory 'only' keywords in Twig includes.
05Modern null handling using ??, ???, and the Craft 5 nullsafe operator (?.).
06Advanced data manipulation patterns using the chainable collect() API for complex filtering.

Casos de Uso

01Ensuring accessibility standards through programmatic heading tags and SVG attribute manipulation.
02Modernizing legacy Craft CMS templates to utilize Craft 5 specific features and functions.
03Building modular, atomic UI components with clear prop definitions and isolation.