CMS Development

DevM
Teilnehmer/-in

Access value in request.cookies object array

lösung

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 Akzeptierte Lösung
miljkovicmisa
Lösung
Stratege/Strategin | Platinum Partner
Stratege/Strategin | Platinum Partner

Access value in request.cookies object array

lösung

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.

Lösung in ursprünglichem Beitrag anzeigen

5 Antworten
miljkovicmisa
Lösung
Stratege/Strategin | Platinum Partner
Stratege/Strategin | Platinum Partner

Access value in request.cookies object array

lösung

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
Teilnehmer/-in

Access value in request.cookies object array

lösung

This is what I needed! Thank you so much!

Teun
Trendsetter/-in | Diamond Partner
Trendsetter/-in | Diamond Partner

Access value in request.cookies object array

lösung

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
Trendsetter/-in | Diamond Partner
Trendsetter/-in | Diamond Partner

Access value in request.cookies object array

lösung

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
Teilnehmer/-in

Access value in request.cookies object array

lösung

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