Templates
dynamic HTML pages from a templating engine with full Go supportProject Forge uses quicktemplate for HTML and SQL templating, providing a fast, type-safe, and efficient templating system. The template system is designed to generate clean, semantic HTML while maintaining excellent performance and developer experience.
Overview
The template system provides: - Type Safety: Compile-time checking of template variables and functions - High Performance: Templates are compiled to Go code for maximum speed - Layout System: Hierarchical layouts with component composition - Component Integration: Seamless integration with Project Forge components - SQL Templates: Type-safe SQL query generation
Basic Template Structure
Page Template Anatomy
Every HTML page template follows a consistent structure with embedded layouts and type-safe data:
1 | |
Template Usage in Controllers
Integrate templates with your controller logic:
1 | |
Template Compilation
Templates are compiled to Go code for optimal performance:
1 | |
Security Considerations
- HTML Escaping: Use
{%s %}for automatic HTML escaping - Raw HTML: Use
{%s= %}only for trusted content - URL Escaping: Use
{%u %}for URL parameters - JavaScript Escaping: Use
{%j %}for JavaScript strings
1 | |
Testing Templates
Template Testing
Test your templates with unit tests:
1 | |
This comprehensive template system provides the foundation for building maintainable, performant, and secure web applications with Project Forge.