PHPackages                             chanondb/symfony7-cookie-consent-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. chanondb/symfony7-cookie-consent-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

chanondb/symfony7-cookie-consent-bundle
=======================================

Symfony bundle for implementing Cookie Consent to comply with AVG/GDPR. for symfony 7

v1.0.27(1y ago)021[1 issues](https://github.com/chanondb/symfony7-cookie-consent-bundle/issues)MITPHPPHP &gt;=7.2

Since Jan 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/chanondb/symfony7-cookie-consent-bundle)[ Packagist](https://packagist.org/packages/chanondb/symfony7-cookie-consent-bundle)[ RSS](/packages/chanondb-symfony7-cookie-consent-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (19)Versions (28)Used By (0)

Cookie Consent bundle for Symfony
=================================

[](#cookie-consent-bundle-for-symfony)

Symfony bundle to append Cookie Consent to your website to comply to AVG/GDPR for cookies. This bundle is tested for Symfony 5. The style works with Bootstrap 5. Bassed on fatalnetwork/symfony-cookie-consent-bundle

Installation
------------

[](#installation)

### Step 1: Download packages

[](#step-1-download-packages)

In a Symfony application run this command to install Cookie Consent bundle in your application

```
composer require chanondb/symfony7-cookie-consent-bundle
```

In a Symfony application run this command to install Bootstrap in your application

```
npm i bootstrap --save-dev
```

### Step 2: Configuration

[](#step-2-configuration)

#### /config/bundles.php

[](#configbundlesphp)

Include the bundle to your project

```
return [
  // ...
  Chanondb\CookieConsentBundle\CookieConsentBundle::class => ['all' => true],
  // ...
];
```

#### /config/packages/cookie\_consent.yaml

[](#configpackagescookie_consentyaml)

Configure your Cookie Consent with the following possible settings

```
cookie_consent:
  categories: # Below are the default supported categories
    - 'analytics'
    - 'marketing'
    - 'preferences'
  use_logger: true # Logs user actions to database
  http_only: true # Sets HttpOnly on cookies
  form_action: $routeName # When set, xhr-Requests will only be sent to this route. Take care of having the route available.
  csrf_protection: true # The cookie consent form is csrf protected or not
  disabled_routes: ['privacy', 'imprint'] # defined controller route names where cookieConsent will not be shown by default
```

#### /config/routes/cookie\_consent.yaml

[](#configroutescookie_consentyaml)

When not using symfony flex, enable the bundles routing manually

```
cookie_consent:
  resource: '@CookieConsentBundle/Resources/config/routing.yaml'
```

### Step 3: Assets

[](#step-3-assets)

#### Bootstrap Style

[](#bootstrap-style)

When enabled SassLoader in your webpack.config.js add the scss file from bootstrap to your project

```
@import '~bootstrap/scss/bootstrap.scss';
```

#### Stimulus Controller

[](#stimulus-controller)

Copy the stimulus controller from Resources/assets/controllers/cookie\_consent\_modal\_controller.js to your controllers folder inside your application (usually /assets/controllers/cookie\_consent\_modal\_controller.js)

#### JS and CSS rebuild

[](#js-and-css-rebuild)

When you set new js oder style (css or scss) files you have to make a rebuild of your public assets

```
npm run dev
```

### Step 4: Database

[](#step-4-database)

When using logger you have to make a migration file

```
php bin/console make:migration
```

After that you can migrate the changes

```
php bin/console doctrine:migration:migrate
```

Usage
-----

[](#usage)

### Twig implementation

[](#twig-implementation)

Load the cookie consent in Twig via render\_esi ( to prevent caching ) at any place you like

```
{{ render_esi(path('cookie_consent.show', {
    route: app.request.attributes.get('_route')
})) }}
{{ render_esi(path('cookie_consent.show_if_cookie_consent_not_set')) }}
```

If you want to load the cookie consent with a specific locale you can pass the locale as a parameter

```
{{ render_esi(path('cookie_consent.show', {
  locale: 'en',
  route: app.request.attributes.get('_route')
})) }}
{{ render_esi(path('cookie_consent.show_if_cookie_consent_not_set', {
  locale: app.request.locale
})) }}
```

Instead of using render\_esi() you can use the render() function

```
{{ render(path('cookie_consent.show', {
    route: app.request.attributes.get('_route')
})) }}
{{ render(path('cookie_consent.show_if_cookie_consent_not_set')) }}
```

### Stimulus implementation

[](#stimulus-implementation)

The stimulus controller needs to implement eg. base.html.twig, make sure the modal is inner this controller

```

  {# ... #}

```

You can set more links for opening the modal like this

```
Cookies
```

### Cookies

[](#cookies)

When a user submits the form the preferences are saved as cookies. The cookies have a lifetime of 1 year. The following cookies are saved

- **Cookie\_Consent**: date of submit
- **Cookie\_Consent\_Key**: Generated key as identifier to the submitted Cookie Consent of the user
- **Cookie*Category*\[CATEGORY\]**: selected value of user (*true* or *false*)

### Logging

[](#logging)

AVG/GDPR requires all given cookie preferences of users to be explainable by the webmasters. For this we log all cookie preferences to the database. IP addresses are anonymized. This option can be disabled in the config.

[![Log](https://raw.githubusercontent.com/fatalnetwork/symfony-cookie-consent-bundle/master/Resources/doc/log.png)](https://raw.githubusercontent.com/fatalnetwork/symfony-cookie-consent-bundle/master/Resources/doc/log.png)

### Themes

[](#themes)

[![View](https://raw.githubusercontent.com/fatalnetwork/symfony-cookie-consent-bundle/master/Resources/doc/view.png)](https://raw.githubusercontent.com/fatalnetwork/symfony-cookie-consent-bundle/master/Resources/doc/view.png)

### TwigExtension

[](#twigextension)

The following TwigExtension functions are available

**cbcookieconsent\_isCategoryAllowedByUser**check if user has given it's permission for certain cookie categories (return bool)

```
{% if cbcookieconsent_isCategoryAllowedByUser('analytics') == true %}
    ...
{% endif %}
```

**cbcookieconsent\_isCookieConsentSavedByUser**check if user has saved any cookie preferences (return bool)

```
{% if cbcookieconsent_isCookieConsentSavedByUser() == true %}
    ...
{% endif %}
```

**cbcookieconsent\_isCookieConsentOpenByDefault**check if the modal view has to open for the user (return string)

```
{% if cbcookieconsent_isCookieConsentOpenByDefault(string current_route, array disabled_routes) == 'true' %}
    ...
{% endif %}
```

Customization
-------------

[](#customization)

### Categories

[](#categories)

You can add or remove any category by changing the config and making sure there are translations available for these categories.

### Translations

[](#translations)

All texts can be altered via Symfony translations by overwriting the CookieConsentBundle translation files. Use the privacy\_route variable inside language files to define the definied route names inside your controller.

### Styling

[](#styling)

CookieConsentBundle comes without an own styling, it is styled from bootstrap. A sass file is available in Resources/assets/css/cookie\_consent.scss and a build css file is available in Resources/public/css/cookie\_consent.css for customization. Each element has a unique class name, so you can change everything.

#### Option SASS

[](#option-sass)

Copy the file Resources/assets/css/cookie\_consent.scss into your project style folder, eg. /assets/styles/cookie\_consent.scss and include this scss file into your /assets/styles/app.scss

```
@import './cookie_consent.scss';
```

#### Option CSS

[](#option-css)

Include the stylesheet in your template, eg. /templates/base.html.twig

```
{% include "@CookieConsent/cookie_consent_styling.html.twig" %}
```

### Javascript

[](#javascript)

By loading Resources/public/js/cookie\_consent.js the cookie consent will be submitted via ajax.

### Events

[](#events)

When a form button is clicked, the event of cookie-consent-form-submit-successful is created. Use the following code to listen to the event and add your custom functionality.

```
document.addEventListener(
  'cookie-consent-form-submit-successful',
  function (e) {
    // ... your functionality
    // ... e.detail is available to see which button is clicked.
  },
  false,
)
```

### Template Themes

[](#template-themes)

You can override the templates by placing templates inside your project (except for Symfony 5 projects):

```
# app/Resources/CookieConsentBundle/views/cookie_consent.html.twig
{% extends '@!CookieConsent/cookie_consent.html.twig' %}

{% block title %}
    Your custom title
{% endblock %}
```

#### Template override for Symfony 5 projects

[](#template-override-for-symfony-5-projects)

You can override the templates by placing templaces inside you project as below. Be careful, it is important to place templates at this location: "app/templates/bundles/CookieConsentBundle/" .

```
# app/templates/bundles/CookieConsentBundle/cookie_consent.html.twig
{% extends '@!CookieConsent/cookie_consent.html.twig' %}

{% block intro %}
    Your custom intro
{% endblock %}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance42

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.4% 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 ~0 days

Total

27

Last Release

484d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea91a3026881212e8b2cca9a100c4d5fd9917a4042aac88953394d41baed171a?d=identicon)[chanondb](/maintainers/chanondb)

---

Top Contributors

[![matthijsch](https://avatars.githubusercontent.com/u/14073380?v=4)](https://github.com/matthijsch "matthijsch (97 commits)")[![chanondb](https://avatars.githubusercontent.com/u/12006385?v=4)](https://github.com/chanondb "chanondb (30 commits)")[![fatalnetwork](https://avatars.githubusercontent.com/u/97599785?v=4)](https://github.com/fatalnetwork "fatalnetwork (21 commits)")[![maartenvanasperen](https://avatars.githubusercontent.com/u/11276046?v=4)](https://github.com/maartenvanasperen "maartenvanasperen (15 commits)")[![reyostallenberg](https://avatars.githubusercontent.com/u/3579090?v=4)](https://github.com/reyostallenberg "reyostallenberg (4 commits)")[![NiklasBr](https://avatars.githubusercontent.com/u/279826?v=4)](https://github.com/NiklasBr "NiklasBr (4 commits)")[![BeatRoy](https://avatars.githubusercontent.com/u/26458713?v=4)](https://github.com/BeatRoy "BeatRoy (2 commits)")[![jaapio](https://avatars.githubusercontent.com/u/1060433?v=4)](https://github.com/jaapio "jaapio (2 commits)")[![xorgxx](https://avatars.githubusercontent.com/u/7679725?v=4)](https://github.com/xorgxx "xorgxx (2 commits)")[![hello-devs](https://avatars.githubusercontent.com/u/30301241?v=4)](https://github.com/hello-devs "hello-devs (1 commits)")[![hectorprats](https://avatars.githubusercontent.com/u/4610023?v=4)](https://github.com/hectorprats "hectorprats (1 commits)")[![mozan](https://avatars.githubusercontent.com/u/6404003?v=4)](https://github.com/mozan "mozan (1 commits)")[![grandmaster44](https://avatars.githubusercontent.com/u/23462753?v=4)](https://github.com/grandmaster44 "grandmaster44 (1 commits)")[![oliverfehmel](https://avatars.githubusercontent.com/u/27670004?v=4)](https://github.com/oliverfehmel "oliverfehmel (1 commits)")[![ensag-dev](https://avatars.githubusercontent.com/u/59049879?v=4)](https://github.com/ensag-dev "ensag-dev (1 commits)")[![RomanApunts](https://avatars.githubusercontent.com/u/62882223?v=4)](https://github.com/RomanApunts "RomanApunts (1 commits)")[![kdefives](https://avatars.githubusercontent.com/u/2663049?v=4)](https://github.com/kdefives "kdefives (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/chanondb-symfony7-cookie-consent-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/chanondb-symfony7-cookie-consent-bundle/health.svg)](https://phpackages.com/packages/chanondb-symfony7-cookie-consent-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)

PHPackages © 2026

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