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
{{= $wsConsent | json }}
JSON output
{
  "alreadySet": false,
  "allAllowed": false,
  "groups": [
    {
      "name": "...",
      "label": "...",
      "description": "...",
      "allowed": false,
      "services": [
        { "name": "...", "label": "...", "description": "...", "allowed": false }
      ]
    }
  ],
  "services": [
    { "name": "...", "label": "...", "description": "...", "allowed": false }
  ],
  "checkAllowed": "ƒ()"
}
Note: "ƒ()" denotes a function. Variables overview
VariableTypeDescription
alreadySetboolWhether the customer has already given consent.
allAllowedboolWhether the customer has agreed to all cookies/services.
groupsarrayConfigured groups, each with their services.
servicesarrayFlat list of all configured services.
Properties of an entry (applies to groups[] as well as services[])
PropertyTypeDescription
namestringTechnical name (for checkAllowed()).
labelstringLabel visible to the customer.
descriptionstringDescription.
allowedboolWhether the entry is allowed (accepted).
servicesarrayOnly for groups[]: the assigned services.
Methods overview
MethodReturn typeDescription
checkAllowed()boolChecks whether a specific service has been accepted.

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.
{{ if not $wsConsent.alreadySet }}
  <!-- Show consent layer -->
{{ /if }}

$wsConsent.allAllowed

Returns whether the customer has agreed to all services (“Allow all” button).
{{ if $wsConsent.allAllowed }}
  <!-- All services have been agreed to -->
{{ /if }}

$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.
{{ foreach $group in $wsConsent.groups }}
  {{= $group.label }}
  {{ foreach $service in $group.services }}
    - {{= $service.label }}
  {{ /foreach }}
{{ /foreach }}

$wsConsent.services

Returns all configured services as a list, regardless of group assignment. The entries carry the properties of an entry.
{{ foreach $service in $wsConsent.services }}
  {{= $service.label }}: {{= $service.allowed }}
{{ /foreach }}

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.
NameTypeRequiredDescription
serviceNamestringyesTechnical name of the service (the name field of an entry).
{{ if $wsConsent.checkAllowed("googleAnalytics") }}
  <!-- Include Google Analytics tracking code -->
{{ /if }}

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.
{{ if $wsConsent.checkAllowed("googleAnalytics") }}
  <script src="https://www.googletagmanager.com/gtag/js?id=..."></script>
{{ /if }}
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.
{{ foreach $group in $wsConsent.groups }}
  <fieldset>
    <legend>{{= $group.label }}</legend>
    <p>{{= $group.description }}</p>
    {{ foreach $service in $group.services }}
      <label>
        <input type="checkbox" name="{{= $service.name }}"{{ if $service.allowed }} checked{{ /if }}>
        {{= $service.label }} – {{= $service.description }}
      </label>
    {{ /foreach }}
  </fieldset>
{{ /foreach }}
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.
{{ if $wsConsent.checkAllowed("youtube") }}
  <!-- e.g. embedded YouTube video -->
{{ else }}
  To see this content, please accept the "Youtube Videos" service.
{{ /if }}
Result
With consent, the content is shown; otherwise the notice.