PHPackages                             seaworn/symfony-htmx-bundle - 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. [API Development](/categories/api)
4. /
5. seaworn/symfony-htmx-bundle

ActiveSymfony-bundle[API Development](/categories/api)

seaworn/symfony-htmx-bundle
===========================

Htmx integration for Symfony

7141PHP

Since Mar 26Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/seaworn/symfony-htmx)[ Packagist](https://packagist.org/packages/seaworn/symfony-htmx-bundle)[ RSS](/packages/seaworn-symfony-htmx-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Symfony Htmx Bundle
===================

[](#symfony-htmx-bundle)

[Htmx](https://htmx.org/) integration for Symfony

- Symfony &gt;=6.0
- PHP &gt;=8.0

Install
-------

[](#install)

`$ composer require seaworn/symfony-htmx-bundle`

Setup
-----

[](#setup)

Add the following snippet to the front controller. This will allow Symfony to use a custom Request class

```
/* public/index.php */

\Symfony\Component\HttpFoundation\Request::setFactory(function (...$args) {
    return new \Seaworn\HtmxBundle\Request\HtmxRequest(...$args);
});
```

Usage
-----

[](#usage)

Extend `Seaworn\HtmxBundle\Controller\AbstractController` (extends `\Symfony\Bundle\FrameworkBundle\Controller\AbstractController`)

```
use Seaworn\HtmxBundle\Request\HtmxRequest;
use Seaworn\HtmxBundle\Response\HtmxResponse;

class HelloController extends \Seaworn\HtmxBundle\Controller\AbstractController{}
```

or use `Seaworn\HtmxBundle\Controller\HtmxControllerTrait`

```
use Seaworn\HtmxBundle\Request\HtmxRequest;
use Seaworn\HtmxBundle\Response\HtmxResponse;

class HelloController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
    use \Seaworn\HtmxBundle\Controller\HtmxControllerTrait;
}
```

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

[](#request-headers)

```
public function index(HtmxRequest $request): HtmxResponse
{
    // whether the request is made via htmx
    $request->isHxRequest();

    // whether the request is via an element using hx-boost attribute
    $request->isHxBoosted();

    // the current browser url
    $request->getHxCurrentUrl();

    // whether request is for history restoration after a miss in the local history cache
    $request->isHxHistoryRestoreRequest();

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

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

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

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

    // ...
}
```

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

[](#response-headers)

```
public function index(HtmxRequest $request): HtmxResponse
{
    // ...
    $response = $this->hxRender('index.html.twig'); // or new HtmxResponse()
    // Optional headers
    $response->setHxLocation(
        "/location",
        [
            'source' => '',
            'event' => '',
            'handler' => '',
            'target' => '',
            'swap' => '',
            'select' => '',
            'values' => [],
            'headers' => [],
        ]) // set HX-Location header
        ->setHxPushUrl('/push') // set HX-Push-Url header
        ->setHxReplaceUrl('/replace') // set HX-Replace-Url header
        ->setHxReswap('outerHTML') // set HX-Reswap header
        ->setHxRetarget('#target') // set HX-Retarget header
        ->setHxReselect('#select') // set HX-Reselect header
        ->setHxTrigger('event') // set HX-Trigger header (simple)
        ->setHxTriggerAfterSwap('event1,event2') // set HX-Trigger-After-Swap header (multiple)
        ->setHxTriggerAfterSettle(['event' => ['key' => 'value']]); // set HX-Trigger-After-Settle header (with detail)
    return $response;
}
```

### Render template block

[](#render--template-block)

```

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

{% block block1 %}

        Sample content...

{% endblock %}
```

```
public function index(HtmxRequest $request): HtmxResponse
{
    return $this->hxRenderBlock('index.html.twig', 'block1');
}
```

### Redirect

[](#redirect)

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

### Refresh

[](#refresh)

```
public function index(HtmxRequest $request): HtmxResponse
{
    return $this->hxRefresh();
}
```

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

[](#stop-polling)

```

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

{% block content %}

        var pollingIndex = 0;
        document.body.addEventListener("polling", function(e) {
            pollingIndex++;
            console.log("Polling Index:", pollingIndex);
        });

{% endblock %}
```

```
public function poll(HtmxRequest $request): HtmxResponse
{
    $index = $request->get('pollingIndex', 0);
    if ((int)$index >= 10) {
        return new HtmxStopPollingResponse();
    }
    return (new HtmxResponse())->setHxTrigger('polling');
}
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance60

Regular maintenance activity

Popularity12

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6907e45b50a902b53c2a33e9b1bfd74cfeeaccba972f15fcb526dea3fcda509a?d=identicon)[seaworn](/maintainers/seaworn)

---

Tags

htmxsymfony

### Embed Badge

![Health badge](/badges/seaworn-symfony-htmx-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/seaworn-symfony-htmx-bundle/health.svg)](https://phpackages.com/packages/seaworn-symfony-htmx-bundle)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M453](/packages/google-gax)

PHPackages © 2026

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