# Eyrie Templates Eyrie is a fast, safe, and ergonomic server-side templating engine for PHP 8.2+. It is designed for the Phred Framework but can be used as a standalone library. ## Features - **High-Performance:** Templates are compiled to native PHP code and cached. - **Security-First:** Automatic output escaping by default to prevent XSS. - **Minimal Syntax:** Clean and predictable syntax optimized for HTML. - **DRY Composition:** Robust template inheritance and reusable components. - **Expressive Control:** Support for conditionals, loops, and range-based iteration. ## Installation Install Eyrie via Composer: ```bash composer require getphred/eyrie ``` ## Quick Start ```php use Eyrie\Engine; use Eyrie\Loader\FileLoader; // 1. Configure the loader $loader = new FileLoader(['./templates']); // 2. Initialize the engine $engine = new Engine($loader, [ 'cache' => './cache', 'debug' => true, ]); // 3. Render a template echo $engine->render('welcome', ['name' => 'Phred']); ``` ## Template Syntax ### Output Use `<< >>` to output variables or expressions. All output is automatically escaped. ```html
2 + 2 = << 2 + 2 >>
``` ### Filters Modify output using the pipe `|` operator. ```html<< title | upper >>
<< bio | raw >>
``` ### Control Structures Control blocks use the `<( )>` syntax. #### Conditionals ```html <( if user.isAdmin )>Welcome, Admin!
<( elseif user.isMember )>Welcome, Member!
<( else )>Welcome, Guest!
<( endif )> ``` #### Loops ```htmlIteration << loop.index >> of << loop.length >>
<( if loop.first )>First item!<( endif )> <( if loop.last )>Last item!<( endif )> <( endloop )> ``` ### Template Inheritance Eyrie supports powerful template inheritance using layouts and blocks. #### Layout (`layouts/base.eyrie.php`) ```html