Aller au contenu
Québec Studio

Extension pour Craft CMS

Cookie Consent Kit

Le consentement aux témoins, fait correctement : aucun témoin tiers avant l’accord du visiteur, et des pages qui restent en cache. Pensé pour la Loi 25.

Craft CMS 5
v5.0.8
Craft CMS 6
v6.0.10
Éditions
Lite (gratuite), Pro
Aussi pour
Statamic, Laravel

La documentation technique est rédigée en anglais, comme dans le dépôt.

Templates — Craft CMS 6

The plugin is reached through craft.consent in Twig and $craft->consent() in Blade.

TwigBladeReturns
craft.consent.banner()$craft->consent()->banner()the banner
craft.consent.render()$craft->consent()->render()echoes the banner
craft.consent.cookieTable(options)$craft->consent()->cookieTable($options)the cookie table
content\|withCookieTable(options)$craft->consent()->withCookieTable($content, $options)content with its markers replaced
craft.consent.categories()$craft->consent()->categories()visible categories and their cookies
craft.consent.videoFacade(id, title, poster)$craft->consent()->videoFacade($id, $title, $poster)a YouTube facade
craft.consent.config()$craft->consent()->config()the resolved configuration

The banner

With autoInject on, the banner is appended to the end of <body> on every site page. With it off, place it yourself:

{{ craft.consent.banner() }}

The banner is rendered once per request. The <head> bootstrap, consent.css and consent.js are registered on every site page whatever autoInject says. A Blade page template needs @craftHead and @craftEndBody for them to be output.

Options are listed in Privacy policy.

{{ craft.consent.cookieTable() }}
{{ craft.consent.cookieTable({ category: 'statistics', headingLevel: 2 }) }}
{{ craft.consent.cookieTable({ classes: { table: 'table table-sm' } }) }}

One section per category, with the template's own prose:

{% for category in craft.consent.categories() %}
    <h2>{{ category.label }}</h2>
    <p>{{ category.description }}</p>
    {{ craft.consent.cookieTable({ category: category.handle, heading: false }) }}
{% endfor %}

Markers in an entry's content — see Markers:

{{ entry.body|withCookieTable }}
{{ entry.body|withCookieTable({ heading: false }) }}
{{ $craft->consent()->withCookieTable($entry->body) }}

As a CKEditor block

  1. Create an entry type with no field, and a default title format.
  2. Add it to the CKEditor field's Entry types.
  3. Add the Add nested content button to the field's toolbar.
  4. Create the partial _partials/entry/<entry-type-handle>.twig in the site's templates:
{{ craft.consent.cookieTable({ headingLevel: 3 }) }}

The editor shows the block as a card; the table appears on the page.

YouTube facade

{{ craft.consent.videoFacade(youtubeId, title) }}
{{ craft.consent.videoFacade(youtubeId, title, posterUrl) }}

An empty id renders nothing. Posters fetched from YouTube are cached in storage/runtime/consent-thumbnails/ and served by the action actions/cookie-consent-kit/thumbnail. See YouTube facade.

Overriding templates

A template in the site's _consent/ folder replaces the plugin's. The folder is the templateRoot setting, inside the site templates folder (resources/views/, or templates/ in a project that has no resources/views/). A folder named after a site handle applies to that site only:

resources/views/_consent/banner.twig
resources/views/english/_consent/banner.blade.php
TemplateRendered by
bannerbanner(), render(), automatic injection
cookie-tablecookieTable(), withCookieTable
video-facadevideoFacade()
video-embedvideoFacade() with videoFacade off

Twig (.twig) and Blade (.blade.php) are both accepted; .twig is used when both exist. Start from the shipped copies in vendor/quebecstudio-mods/consent-kit-core/resources/views/ (blade/ or twig/).

Variables

TemplateVariablesDerived variables
bannerconfig, texts, categoriesqsmConfigJson
cookie-tablecategories, texts, classes, heading, headingLevelqsmLevel; per category qsmTitleId; per cookie qsmProviderLabel
video-facadeyoutubeId, title, poster, thumbnail, consentCategory, textsqsmPosterUrl
video-embedyoutubeId, titleqsmIframeTitle

The qsm-ck variables are computed by the plugin so a template holds no logic:

VariableValue
qsmConfigJsonconfig as JSON, safe inside <script>
qsmLevelheadingLevel bounded to 2–6, 3 when empty
qsmTitleIdqsm-ck-inventory-<handle>
qsmProviderLabelthe provider, or texts.firstParty
qsmPosterUrlposter, else thumbnail
qsmIframeTitletitle, else YouTube

Keep the data-qsm-ck-* attributes: the script finds every control through them.

Une extension Craft CMS qui n’existe pas encore?

Si Craft CMS ne fait pas encore ce dont vous avez besoin, on peut le développer pour vous.

Parlons-en

Nous utilisons des témoins

Ce site utilise des témoins (« cookies ») nécessaires à son fonctionnement. Avec votre accord, nous en utilisons aussi pour mesurer la fréquentation. Vous pouvez changer d'avis en tout temps. Politique de confidentialité

Vos préférences de témoins

Toujours actif

Indispensables au fonctionnement du site et à la sécurité des formulaires. Ils ne peuvent pas être désactivés.

Nécessaires
Témoin Déposé par Finalité Conservation
CraftSessionId Ce site Maintient votre session de navigation. Session
CRAFT_CSRF_TOKEN Ce site Protège les formulaires contre la falsification de requête. Session
cookie_consent Ce site Mémorise vos choix en matière de témoins. 6 mois

Nous aident à comprendre comment le site est utilisé, afin de l’améliorer. Mesurées avec Matomo.

Statistiques
Témoin Déposé par Finalité Conservation
_pk_id.* Ce site Reconnaît le navigateur d’une visite à l’autre, sans vous identifier. 13 mois
_pk_ses.* Ce site Regroupe les pages vues pendant une même visite. 30 minutes