Skip to main content
With the $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 statusalreadySet (has the customer made any decision yet?) and allAllowed (have they agreed to everything?). Use these to control whether the consent layer needs to be displayed at all.
  • Structured listgroups with their services, to build a consent layer.
  • Targeted checkcheckAllowed(serviceName), to check the consent before loading a specific script. This is the recommended way to embed external scripts.
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
JSON output
Note: "ƒ()" denotes a function. Variables overview Properties of an entry (applies to groups[] as well as services[]) Methods overview

Templates

The consent layer can be called globally and is loaded from the template consent.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 under services. 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 value
booltrue if the service has been accepted, otherwise false.

Actions

Actions for this module (set, change, save consent) are documented separately: Actions → Consent.

Examples

Embeds a script only if the corresponding service has been accepted. If consent is missing, the script is not written into the page.
Result
The tracking script appears in the source only if the customer has accepted “Google Analytics”.
Iterates over the groups and, for each group, its services, which reflects the typical structure of a consent layer.
Result
One block per group with the contained services; services already accepted are checked.
Shows content that requires consent (e.g. an embedded video) only if the service has been accepted; otherwise a notice is displayed.
Result
With consent, the content is shown; otherwise the notice.