CMS Development

DevM
Participant

Access value in request.cookies object array

SOLVE

I'm using the following code to retreive and display the cookie info from my site:

{% set user_info = [request.cookies.officerInfo] %}
{{user_info}}

 

{{user_info}} successfully displays the information in the cookie like this:

{"fname":"Admin","lname":"Testing","crm_id":"010101"}

 

I have a field in a 3rd party form where I need to put the crm id "010101".

I've tried various things like {{user_info.crm_id}} or {{user_info[2]}} without success.

Can someone help point me in the right direction? Thanks!

0 Upvotes
1 Accepted solution
miljkovicmisa
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Access value in request.cookies object array

SOLVE

Hello @DevM , since {{user_info}} returns a json string, you can convert that to a hubl object with the fromjson so you can access its keys like you tried to. So the snippet would look something like this:

 

 

{% set user_info_json = user_info %}
{% set user_info_obj = user_info_json|fromjson %}<br>
{{user_info_obj.crm_id}}

 

 

You can learn more about the fromjson filter right here in this link.

 

If my answer was helpful please mark it as a solution.

View solution in original post

5 Replies 5
miljkovicmisa
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Access value in request.cookies object array

SOLVE

Hello @DevM , since {{user_info}} returns a json string, you can convert that to a hubl object with the fromjson so you can access its keys like you tried to. So the snippet would look something like this:

 

 

{% set user_info_json = user_info %}
{% set user_info_obj = user_info_json|fromjson %}<br>
{{user_info_obj.crm_id}}

 

 

You can learn more about the fromjson filter right here in this link.

 

If my answer was helpful please mark it as a solution.

DevM
Participant

Access value in request.cookies object array

SOLVE

This is what I needed! Thank you so much!

Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Access value in request.cookies object array

SOLVE

Yep, this is most likely the solution. Thanks @miljkovicmisa !



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Access value in request.cookies object array

SOLVE

Hi @DevM ,

 

Why are you wrapping the request.cookies in an array? ([request.cookies.officerInfo])
Does it not work if you use {% set user_info = request.cookies.officerInfo %} ?

 

Could you use the |pprint filter to check the output of user_info? {{user_info|pprint}}



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


DevM
Participant

Access value in request.cookies object array

SOLVE

I tried a variety of things and had left the brackets by accident on my question - thank you for catching that.

Using pprint helped me see what the output was but I'm still trying to narrow my selection down.

0 Upvotes