简体   繁体   中英

Getting cookie as a HubL variable

In HubSpot I'm trying to check if a cookie exists, if it does exist, I'm looking to perform an action through an if statement . However, I cannot seem to get the cookie value using request.cookies as outlined in their docs .

Doing the following:

{% set cookies = request.cookies %}
{{ cookies }}

Returns all the cookies. I'm looking to obtain a single cookie value in a variable.

The cookie I'm trying to obtain in a variable is named __hssluid . Since request.cookies is of type dict , I've tried the following:

{% set cookie_name = "__hssluid" %}
{% set result = request.cookies.cookie_name %}
{{ result }}

But it doesn't show anything. How can I get a single cookies value using HuBL?

Have also tried the following:

{% set cookie_name = "__hssluid" %}
{{ request.cookies[cookie_name] }}
{{ request.cookies.cookie_name }}
{{ request.cookies.__hssluid }}

All the above prints nothing for me.

To get a value of a cookie with HUBL you just need to do:

{{ request.cookies.cookie_name }}

without setting the cookie_name as a variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM