# Blade templates (oxblade-icons)

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

- Package: oxblade-icons (Rust, alpha), crates: `oxblade-icons`
- Maintenance: active; Latest release: 0.1.0 (2026-12-05); MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/oxblade-icons), [crates.io](https://crates.io/crates/oxblade-icons/0.1.0), [docs.rs](https://docs.rs/oxblade-icons/0.1.0), [Changelog](https://oss.bowerbird.si/oxblade-icons/docs/changelog/), [Contributing](https://github.com/bowerbird-si/oxblade-icons/blob/c7e0252d5f06a12c2c4687fa63a4aa97d51b0e4c/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/oxblade-icons/blob/c7e0252d5f06a12c2c4687fa63a4aa97d51b0e4c/SECURITY.md)
- Based on: [blade-ui-kit/blade-icons](https://github.com/driesvints/blade-icons): The PHP renderer and template behavior this package ports.
- PHP parity: core (4 covered, 4 diverged, 3 planned of 11 abilities; 14 fixtures; follows blade-ui-kit/blade-icons 1.11.0; verified 2026-12-05)
- HTML version: https://oss.bowerbird.si/oxblade-icons/docs/blade/
- Source: https://github.com/bowerbird-si/oxblade-icons/blob/c7e0252d5f06a12c2c4687fa63a4aa97d51b0e4c/docs/blade.md

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:

```rust
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](https://oss.bowerbird.si/oxblade-icons/docs/laravel/) instead; it registers the same extensions.

## The four forms

```blade
{{ 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:

```blade
@svg('heroicon-o-home', 'size-6', { title: 'Home' })
```

| Form | Arguments | Missing icon |
| --- | --- | --- |
| `svg(name, …)` helper | the icon name, then a class string, an attribute map, or a class string and a map | uses fallbacks, then fails the render |
| `@svg(name, …)` directive | the same as the helper | uses fallbacks, then fails the render |
| `<x-icon name="…">` | `name`, then any attributes; `class` becomes the call's class | uses fallbacks, then fails the render |
| `<x-{prefix}-{icon}>` | any attributes | fails 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:

```rust
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](https://oss.bowerbird.si/oxblade-icons/docs/rendering/). There is no `defer` support in templates either.
