Hello Grav community,
I'm trying to establish clear guidelines for when to use the raw filter versus the |e('html') filter in Twig templates, and would appreciate your expertise.
From my understanding:
-
The
rawfilter is used for trusted HTML content (likepage.content) -
The
|e('html')filter is commonly applied tosite.titleand sometimespage.titlein default themes
My questions:
-
Trusted content clarification: If site and page titles are managed by authenticated users with admin permissions, shouldn't they be considered "trusted" and safe to output without HTML escaping? Why do templates typically escape them?
-
Consistency requirement: If HTML escaping is recommended for titles, should this be applied consistently across all contexts where these titles appear (meta tags, aria-labels, alt attributes, etc.)?
-
Are there specific security concerns with title fields that I might be overlooking?
I want to ensure I'm following both security best practices and Grav's intended patterns. Thank you for your guidance!