$wsConsent module, you read the customer’s consent to cookies and services and use it to control which content and external scripts are loaded. This lets you, for example, embed a tracking or marketing service only after the customer has agreed to it.
This page is about reading the consent status. Setting the consent (accepting, declining, saving the selection) is done via actions and is documented separately under Actions → Consent. The associated cookies themselves are handled by the $wsCookies module.
Basic concept
The consent is organized in two stages: groups (e.g. “Statistics”, “Marketing”) bundle individual services (e.g. “Google Analytics”). The customer can either agree to all (“Allow all”) or make a selection per group/service. Each entry carries an “allowed” flag that reflects the decision.$wsConsent provides this status in the following ways:
- Overall status –
alreadySet(has the customer made any decision yet?) andallAllowed(have they agreed to everything?). Use these to control whether the consent layer needs to be displayed at all. - Structured list –
groupswith theirservices, to build a consent layer. - Targeted check –
checkAllowed(serviceName), to check the consent before loading a specific script. This is the recommended way to embed external scripts.
Consent decides whether the script is loaded at all
Template code runs when the page is built. If you wrap a script with{{ if $wsConsent.checkAllowed(...) }}, the script is not even written into the page when consent is missing — it is not just hidden. This ensures that a declined service really does not load.
Module overview
Example / excerpt of$wsConsent
"ƒ()" denotes a function.
Variables overview
| Variable | Type | Description |
|---|---|---|
alreadySet | bool | Whether the customer has already given consent. |
allAllowed | bool | Whether the customer has agreed to all cookies/services. |
groups | array | Configured groups, each with their services. |
services | array | Flat list of all configured services. |
groups[] as well as services[])
| Property | Type | Description |
|---|---|---|
name | string | Technical name (for checkAllowed()). |
label | string | Label visible to the customer. |
description | string | Description. |
allowed | bool | Whether the entry is allowed (accepted). |
services | array | Only for groups[]: the assigned services. |
| Method | Return type | Description |
|---|---|---|
checkAllowed() | bool | Checks whether a specific service has been accepted. |
Templates
The consent layer can be called globally and is loaded from the templateconsent.htm.
Variables
$wsConsent.alreadySet
Returns whether the customer has already set a cookie/service consent. Use it, for example, to show the consent layer only when no decision has been made yet.$wsConsent.allAllowed
Returns whether the customer has agreed to all services (“Allow all” button).$wsConsent.groups
Returns the configured groups. Each group carries the properties of an entry and contains the assigned services underservices. Use the groups to build a structured consent layer.
$wsConsent.services
Returns all configured services as a list, regardless of group assignment. The entries carry the properties of an entry.Methods
$wsConsent.checkAllowed()
Checks whether a specific service has been accepted by the customer. This is the recommended way to check consent before loading an external script, because the script is not rendered at all if consent is missing. Signature$wsConsent.checkAllowed(serviceName)
Return valuebool – true if the service has been accepted, otherwise false.
| Name | Type | Required | Description |
|---|---|---|---|
serviceName | string | yes | Technical name of the service (the name field of an entry). |
Actions
Actions for this module (set, change, save consent) are documented separately: Actions → Consent.Examples
Load an external script depending on consent
Embeds a script only if the corresponding service has been accepted. If consent is missing, the script is not written into the page.The tracking script appears in the source only if the customer has accepted “Google Analytics”.
Build a consent layer from groups and services
Iterates over the groups and, for each group, its services, which reflects the typical structure of a consent layer.One block per group with the contained services; services already accepted are checked.
Show content only with consent
Shows content that requires consent (e.g. an embedded video) only if the service has been accepted; otherwise a notice is displayed.With consent, the content is shown; otherwise the notice.
Related links
- Actions → Consent – set and save the consent (this module only reads it).
- $wsCookies – the cookies controlled by the consent.
