numero2/contao-cookie-consent 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

numero2/contao-cookie-consent

Composer 安装命令:

composer require numero2/contao-cookie-consent

包简介

A cookie consent solution for Contao CMS - the drop-in replacement for the cookie consent functionality of Contao Marketing Suite.

README 文档

README

Packagist Version License: LGPL v3

A cookie consent solution for Contao CMS - the drop-in replacement for the cookie consent functionality of Contao Marketing Suite.

Screenshot

Cookie Consent in Light and Dark mode

Cookie Consent in Light and Dark mode

Requirements

Installation

Via Contao Manager or Composer:

composer require numero2/contao-cookie-consent

Insert Tags

Use 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.

Examples

{{ifoptin::6}}<p>You have accepted ACME cookies.</p>{{ifoptin}}

{{ifnoptin::6}}<p>Please accept ACME cookies to see this content.</p>{{ifnoptin}}

Styling

Colors

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.

Color scheme

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')
%}

Developer API

This bundle exposes helper utilities to check cookie consent status programmatically - both in PHP/Symfony and in Twig templates.

PHP / Symfony

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();
    }
}

Twig

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 fallback optin dialog for the given tag #}
{{ cc_tag_fallback(6) }}

{# Render a link that opens the consent dialog (optional: custom CSS ID) #}
{{ cc_consent_force_link('customCSSId') }}

HTTP-Cache

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.

Disclaimer

Cookie storage

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).

Consent Logs

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.

Legal stuff

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.

numero2/contao-cookie-consent 适用场景与选型建议

numero2/contao-cookie-consent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cookie」 「contao」 「cookieconsent」 「consent」 「cookiebar」 「opt-in」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 numero2/contao-cookie-consent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 numero2/contao-cookie-consent 我们能提供哪些服务?
定制开发 / 二次开发

基于 numero2/contao-cookie-consent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 60
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 39
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0
  • 更新时间: 2026-03-25