# Mojolicious
$self->plugin('HTMX');
# Mojolicious::Lite
plugin 'HTMX';
get '/trigger' => 'trigger';
post '/trigger' => sub ($c) {
state $count = 0;
$count++;
$c->htmx->res->trigger(showMessage => 'Here Is A Message');
$c->render(text => "Triggered $count times");
};
@@ template.html.ep
<html>
<head>
%= app->htmx->asset
</head>
<body>
<h1>Mojolicious::Plugin::HTMX<h1>
<main>
%= content
</main>
</body>
</html>
@@ trigger.html.ep
% layout 'default';
<h1>Trigger</h1>
<button hx-post="/trigger">Click Me</button>
<script>
document.body.addEventListener("showMessage", function(e){
alert(e.detail.value);
});
</script>
To install this module type the following:
perl Makefile.PL
make
make test
make install
Using App::cpanminus:
cpanm Mojolicious::Plugin::HTMX
perldoc Mojolicious::Plugin::HTMX
- https://metacpan.org/release/Mojolicious-Plugin-HTMX
Copyright (C) 2022-2023 by Giuseppe Di Terlizzi