PHPackages                             tomcri/htmxfony - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tomcri/htmxfony

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tomcri/htmxfony
===============

Htmx SDK for Symfony

1.4.1(8mo ago)473.0k5MITPHPPHP &gt;=7.1

Since Nov 8Pushed 8mo ago6 watchersCompare

[ Source](https://github.com/tomcri/htmxfony)[ Packagist](https://packagist.org/packages/tomcri/htmxfony)[ RSS](/packages/tomcri-htmxfony/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (6)Dependencies (5)Versions (10)Used By (0)

### Symfony sdk for [htmx](https://htmx.org/)

[](#symfony-sdk-for-htmx)

- Symfony 5.4 or greater
- PHP 7.1 or greater

### Installation

[](#installation)

#### Composer

[](#composer)

```
composer require tomcri/htmxfony
```

#### Configuration

[](#configuration)

In order to use `HtmxResponse` in Controllers, Listeners, EventSubscribers, etc..., `HtmxKernelTrait` must be included in the Kernel class:

```
/* src/Kernel.php: */

class Kernel extends BaseKernel
{
    ...
    use HtmxKernelTrait;

    ...
}
```

### Usage

[](#usage)

#### [Request headers](https://htmx.org/docs/#request-headers)

[](#request-headers)

```
use HtmxControllerTrait;

public function index(HtmxRequest $request): Response
{
    // indicates that the request is via an element using hx-boost
    $request->isBoosted();

    // the current URL of the browser
    $request->getCurrentUrl();

    // true if the request is for history restoration after a miss in the local history cache
    $request->isHistoryRestoreRequest();

    // the user response to an hx-prompt
    $request->getPromptResponse();

    // true if the request is made by Htmx
    $request->isHtmxRequest();

    // he id of the target element if it exists
    $request->getTargetId();

    // the name of the triggered element if it exists
    $request->getTriggerName();

    // the id of the triggered element if it exists
    $request->getTriggerId();
...
```

#### [Response headers](https://htmx.org/docs/#response-headers)

[](#response-headers)

```
use HtmxControllerTrait;

public function index(HtmxRequest $request): Response
{
    ...

    return $this->htmxRender('homepage/index.html.twig') // or new HtmxResponse()
        // Optional headers:
        ->setLocation(new HtmxLocation( // allows you to do a client-side redirect that does not do a full page reload. (https://htmx.org/headers/hx-location/)
            "/location", // path
            'testsource', // the source element of the request
            null, // an event that “triggered” the request
            null, // a callback that will handle the response HTML
            "#testdiv", // the target to swap the response into
            'outerHTML', // how the response will be swapped in relative to the target
            ['test' => 'test'], // values to submit with the request
            ['X-Test' => 'test'], // headers to submit with the request
        ))
        ->setPushUrl('/push') // pushes a new url into the history stack
        ->setReplaceUrl('/replace') // replaces the current URL in the location bar
        ->setReSwap('outerHTML') // allows you to specify how the response will be swapped. See hx-swap for possible values
        ->setReTarget('#testdiv') // a CSS selector that updates the target of the content update to a different element on the page
        ->setReSelect('#testdiv') // a CSS selector that allows you to choose which part of the response is used to be swapped in. Overrides an existing hx-select on the triggering element
        ->setTriggers( // allows you to trigger client-side events (https://htmx.org/headers/hx-trigger/)
            new HtmxTrigger('trigger1'), // simple trigger
            new HtmxTrigger('trigger2', 'trigger2 message'), // trigger with string value
            new HtmxTrigger('trigger3', [ // trigger with array value
                'prop1' => 'value1',
                'prop2' => 'value2',
            ]),
            new HtmxTrigger('trigger4', $object) // trigger with object value, object must implements JsonSerializable interface
        )
        ->setTriggersAfterSettle() // allows you to trigger client-side events after the settle step
        ->setTriggerAfterSwap() // allows you to trigger client-side events after the swap step
        ;
}
...
```

#### [Render blocks of a template](https://htmx.org/docs/#oob_swaps)

[](#render-blocks-of-a-template)

```

{% extends 'layout.html.twig' %}

{% block block1 %}

        block1 content

{% endblock block1 %}

{% block block2 %}

        block2 content

{% endblock block2 %}
```

```
use HtmxControllerTrait;

public function index(HtmxRequest $request): Response
{
    return $this->htmxRenderBlock( //render one or more blocks of a template
        new TemplateBlock('homepage/index.html.twig', 'block1', [/*params*/]),
        new TemplateBlock('homepage/other.html.twig', 'block2', [/*params*/]),
    );
}
...
```

#### Refresh

[](#refresh)

```
use HtmxControllerTrait;

public function index(HtmxRequest $request): Response
{
    return $this->htmxRefresh();
}
...
```

#### Redirect

[](#redirect)

```
use HtmxControllerTrait;

public function index(HtmxRequest $request): Response
{
    return $this->htmxRedirect('https://htmx.org/');
}
...
```

#### Stop [polling](https://htmx.org/docs/#polling)

[](#stop-polling)

```

{% extends 'layout.html.twig' %}

{% block body %}

        window.pollingIndex = 0;
        document.body.addEventListener("polling", function(evt){
            window.pollingIndex++;
            console.log("polling: " + pollingI);
        });

{% endblock body %}
```

```
use HtmxControllerTrait;

public function polling(HtmxRequest $request): Response
{
    if ((int)$request->get('i', 0) >= 2) {
        return new HtmxStopPollingResponse();
    }

    return (new HtmxResponse())->setTriggers(
        new HtmxTrigger('polling')
    );
}
...
```

### Tests

[](#tests)

```
composer test
```

### Coding Standards

[](#coding-standards)

```
composer cs:check
composer cs:fix
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance61

Regular maintenance activity

Popularity32

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~102 days

Recently: every ~156 days

Total

8

Last Release

247d ago

Major Versions

0.0.1 → 1.0.02023-11-09

PHP version history (2 changes)0.0.1PHP &gt;=8.1

1.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/24bb310750d148ac7dbfcc4b3abf3438992434e1ce33a98c841ec4016bd0f52f?d=identicon)[tomcri](/maintainers/tomcri)

---

Top Contributors

[![tomcri](https://avatars.githubusercontent.com/u/28981295?v=4)](https://github.com/tomcri "tomcri (7 commits)")[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (3 commits)")[![steefmin](https://avatars.githubusercontent.com/u/5700620?v=4)](https://github.com/steefmin "steefmin (2 commits)")[![tacman](https://avatars.githubusercontent.com/u/619585?v=4)](https://github.com/tacman "tacman (2 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/tomcri-htmxfony/health.svg)

```
[![Health](https://phpackages.com/badges/tomcri-htmxfony/health.svg)](https://phpackages.com/packages/tomcri-htmxfony)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[symfony/web-profiler-bundle

Provides a development tool that gives detailed information about the execution of any request

2.3k160.5M1.2k](/packages/symfony-web-profiler-bundle)[kimai/kimai

Kimai - Time Tracking

4.8k9.0k1](/packages/kimai-kimai)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

567.3M140](/packages/symfony-ux-icons)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
