Module ember

Source
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§

EmberConfig
Template engine configuration
EmberData
Template data container for passing variables to templates
EmberEngine
Template engine instance
EmberError
Template compilation error

Enums§

EmberValue
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