Skip to content

giterlizzi/perl-Mojolicious-Plugin-HTMX

Repository files navigation

Release Actions Status License Starts Forks Issues Coverage Status

Mojolicious::Plugin::HTMX - </> htmx plugin for Mojolicious

Usage

# 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>

Installation

To install this module type the following:

perl Makefile.PL
make
make test
make install

Using App::cpanminus:

cpanm Mojolicious::Plugin::HTMX

Documentation

Copyright

Copyright (C) 2022-2023 by Giuseppe Di Terlizzi

About

Mojolicious::Plugin::HTMX - </> htmx plugin for Mojolicious

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages