Expand description
§Ember Template Engine
A powerful, Laravel Blade-inspired templating engine for Torch. Ember provides a clean, expressive syntax for building dynamic HTML templates.
§Features
- Blade-like syntax: Familiar
@if
,@foreach
,@extends
,@section
directives - Template inheritance: Build layouts and extend them
- Component system: Reusable template components
- Automatic escaping: XSS protection by default
- Template caching: Compiled templates are cached for performance
- Hot reloading: Templates are recompiled when changed in development
§Example
use torch_web::{App, Response, ember::*};
async fn home() -> Response {
let data = EmberData::new()
.with("title", "Welcome to Torch")
.with("users", vec!["Alice", "Bob", "Charlie"]);
ember("home", data).await
}
Template file templates/home.ember
:
@extends('layout')
@section('content')
<h1>{{ $title }}</h1>
@if(count($users) > 0)
<ul>
@foreach($users as $user)
<li>{{ $user }}</li>
@endforeach
</ul>
@else
<p>No users found.</p>
@endif
@endsection
Structs§
- Ember
Config - Template engine configuration
- Ember
Data - Template data container for passing variables to templates
- Ember
Engine - Template engine instance
- Ember
Error - Template compilation error
Enums§
- Ember
Value - Values that can be passed to templates
Functions§
- ember
- Render a template using the global Ember engine
- ember_
view - Render a template with no data