CMS Development

DevM
Participante

Access value in request.cookies object array

resolver

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 Avaliação positiva
1 Solução aceita
miljkovicmisa
Solução
Top colaborador(a) | Parceiro Platinum
Top colaborador(a) | Parceiro Platinum

Access value in request.cookies object array

resolver

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.

Exibir solução no post original

5 Respostas 5
miljkovicmisa
Solução
Top colaborador(a) | Parceiro Platinum
Top colaborador(a) | Parceiro Platinum

Access value in request.cookies object array

resolver

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
Participante

Access value in request.cookies object array

resolver

This is what I needed! Thank you so much!

Teun
Especialista reconhecido(a) | Parceiro Diamante
Especialista reconhecido(a) | Parceiro Diamante

Access value in request.cookies object array

resolver

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
Especialista reconhecido(a) | Parceiro Diamante
Especialista reconhecido(a) | Parceiro Diamante

Access value in request.cookies object array

resolver

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
Participante

Access value in request.cookies object array

resolver

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 Avaliação positiva