A cookie consent solution for Contao CMS - the drop-in replacement for the cookie consent functionality of Contao Marketing Suite.
Cookie Consent in Light and Dark mode
- Contao 5.7 or newer
Via Contao Manager or Composer:
composer require numero2/contao-cookie-consentUse these insert tags directly in your Contao templates and content elements to control cookie consent dependent output.
| Tag | Description |
|---|---|
{{cc_optinlink}} |
Renders a link that reopens the cookie consent dialog, allowing the user to adjust their consent. After confirming, the page scrolls back to the original element automatically. |
{{ifoptin::*}} |
Wraps content that is only shown if the user has accepted the specified tag. Replace * with the tag ID. |
{{ifnoptin::*}} |
Wraps content that is only shown if the user has not accepted the specified tag. Replace * with the tag ID. |
{{ifoptin::6}}<p>You have accepted ACME cookies.</p>{{ifoptin}}
{{ifnoptin::6}}<p>Please accept ACME cookies to see this content.</p>{{ifnoptin}}
Colors can be customized via CSS custom properties. Example:
cc-cookie-consent, cc-cookie-optin {
--cc-accent: #f47c00;
}A full list of available CSS custom properties can be found in contao/templates/styles/cc_default.html.twig.
By default, both elements follow the color scheme defined by the user's operating system or browser. If your page layout requires a specific scheme, it can be enforced via a custom template:
{% extends '@Contao/frontend_module/cc_cookie_consent.html.twig' %}
{% set attributes = attrs(attributes|default)
.set('color-scheme', 'light')
%}This bundle exposes helper utilities to check cookie consent status programmatically - both in PHP/Symfony and in Twig templates.
Inject the numero2_cookie_consent.util.cookie_consent service into your controller or service:
// src/Controller/MyCustomController.php
namespace App\Controller;
use numero2\CookieConsentBundle\Util\CookieConsentUtil;
class MyCustomController
{
public function __construct(
private readonly CookieConsentUtil $cookieConsentUtil
) {}
public function __invoke(): void
{
// Returns true if the tag with ID 6 has been accepted
$this->cookieConsentUtil->isTagAccepted(6);
// Returns true if the tag with ID 6 has NOT been accepted
$this->cookieConsentUtil->isTagNotAccepted(6);
// Generates a link that triggers the consent dialog
$this->cookieConsentUtil->generateConsentForceLink();
}
}Three global Twig functions are available:
{# Show content only if tag ID 6 was accepted #}
{% if cc_tag_accepted(6) %}
<p>Analytics is enabled.</p>
{% endif %}
{# Show content only if tag ID 6 was NOT accepted #}
{% if cc_tag_not_accepted(6) %}
<p>Please enable Analytics to see this content.</p>
{% endif %}
{# Render a link that opens the consent dialog (optional: custom CSS ID) #}
{{ cc_consent_force_link('customCSSId') }}Should work as expected for other Contao entities such as content elements, modules, articles, pages, etc. This means that whenever a tag or tag group is created, edited, or deleted, the corresponding cache entries will be invalidated.
However, be aware that we do not support cache invalidation based on function usage, e.g. $this->cookieConsentUtil->isTagAccepted(<id>), or in Twig {% if cc_tag_not_accepted(<id>) %}.
Also, the insert tag {{ifoptin::<id>}} can only affect the rendered markup based on the tag configuration itself.
This bundle manages cookie consent on behalf of your Contao installation. Any cookies set during the consent process belong to your website - no data is transmitted to or stored by us.
The following cookies are set by this bundle:
| Cookie | Value | Lifetime | Purpose |
|---|---|---|---|
cc_cookies |
List of tag group IDs | 7 days by default, configurable | Stores which tag groups the user has accepted (if any). |
This bundle does not maintain any server-side logs of individual user consent. As the extension does not require user accounts, it is technically impractical to link a consent decision to a specific individual or IP address. Instead, user consent - or rejection - is recorded exclusively via a cookie stored on the user’s device. This approach ensures that consent can be reliably verified for each user while avoiding the storage of personal data on the server, in line with GDPR principles of data minimization and privacy by design.
Please use this bundle at your own risk. Whether your specific setup is legally compliant is something we cannot assess - if you're uncertain, a lawyer is the right contact. For technical questions, though, we're happy to help.
