Blade templates

oxblade-icons Alpha Rust

The blade feature registers four ways to render an icon in oxblade templates: the svg() helper, the @svg directive, <x-icon> and one component prefix per set.

Register

Build the registry, then pass it to blade::register while building the oxblade environment:

use std::sync::Arc;

use oxblade::{engine::Environment, loader::MemoryLoader};
use oxblade_icons::{Icons, blade, icon_set};

let icons = Icons::builder().set(icon_set!(oxblade_heroicons)).build()?;
let env = blade::register(Environment::builder(MemoryLoader::new()), Arc::new(icons)).build();

The integration targets oxblade 0.2. In a Laravel for Rust application, use the service provider instead; it registers the same extensions.

The four forms

{{ svg('heroicon-o-home', 'size-6') }}
@svg('heroicon-o-home', 'size-6')
<x-icon name="heroicon-o-home" class="size-6" />
<x-heroicon-o-home class="size-6" />

All four render the same <svg class="size-6" …> markup. Use an oxblade map for attributes:

@svg('heroicon-o-home', 'size-6', { title: 'Home' })
FormArgumentsMissing icon
svg(name, …) helperthe icon name, then a class string, an attribute map, or a class string and a mapuses fallbacks, then fails the render
@svg(name, …) directivethe same as the helperuses fallbacks, then fails the render
<x-icon name="…">name, then any attributes; class becomes the call's classuses fallbacks, then fails the render
<x-{prefix}-{icon}>any attributesfails the render; fallbacks are not used

The prefix component fails on a missing icon because in Blade Icons a component only exists for an icon that exists. The other forms fall back like Icons::svg.

Component attributes follow oxblade's usual rules: a bare attribute such as x-cloak arrives as true and renders as x-cloak="1". Values that oxblade marks as HTML are passed as Trusted; plain values are text.

Options

blade::register_with takes blade::Options to change which components are installed:

use oxblade_icons::blade::{self, Options};

let options = Options::new()
    .icon_component(Some("svg-icon")) // <x-svg-icon name="…"> instead of <x-icon>
    .set_components(true);            // keep <x-heroicon-o-home />
let env = blade::register_with(Environment::builder(MemoryLoader::new()), Arc::new(icons), &options).build();

icon_component(None) leaves out the generic component, and set_components(false) leaves out the prefix components. The helper and the directive are always registered.

Rendering is the same as in Rust

Every form calls the same registry, so defaults, fallbacks, titles, attribute checks and errors work as described in Rendering icons. There is no defer support in templates either.