NAME
Uniform::HTMX::Dancer2 - HTMX integration for Dancer2 applications
VERSION
Version 1.00
SYNOPSIS
use Dancer2;
use Uniform::HTMX::Dancer2;
get '/items' => sub {
if (is_htmx) {
htmx->res_retarget('#item-list');
htmx->res_trigger('itemsLoaded', { count => 10 });
return template 'partials/items' => {}, { layout => undef };
}
return template 'full_page';
};
DESCRIPTION
Uniform::HTMX::Dancer2 integrates the Uniform::HTMX engine into Dancer2 applications. It exposes lightweight DSL keywords to inspect incoming HTMX headers and modify outgoing response headers seamlessly within route handlers.
Internally this plugin builds a per-request Uniform::HTMX instance with Uniform::HTMX->driver, extracting inbound headers from the Dancer2 request and, via an after hook, writing any accumulated outbound headers back onto the Dancer2 response automatically - you never need to call apply yourself.
DSL KEYWORDS
htmx
my $htmx_obj = htmx;
Returns the Uniform::HTMX instance bound to the current request/response. The same instance is returned on every call within a single request, so accumulated response headers are shared. All core Uniform::HTMX methods can be invoked directly:
htmx->target; # Read HX-Target header
htmx->prompt; # Read HX-Prompt header
htmx->res_trigger('saved', { id => 42 }); # Set HX-Trigger header with JSON
htmx->res_retarget('#main-content'); # Set HX-Retarget header
is_htmx
if (is_htmx) { ... }
Convenience helper that returns boolean 1 if the current request was initiated by HTMX (i.e., HX-Request is present and true), or 0 otherwise.
SEE ALSO
AUTHOR
Joshua S. Day <HAX@cpan.org>
LICENSE AND COPYRIGHT
Copyright (c) 2026 Joshua S. Day.
This program is free software; you can redistribute it and/or modify it under the terms of the MIT License.