Hi I'm sure this is simple but it is eluding me. I want to pull out all the user profile fields with twig as an array that I can then check. When I dump the user or currentUser data it does not show any of the profile fields I have created in the returned object. I can however still access these fields with user.customfieldname. How can I return the array I am looking for?
1 Answer
Custom field data is accessible via currentUser.getContent()
.
Using dump
:
{{ dump(currentUser.getContent()) }}
Or to output as string:
{{ currentUser.getContent()|join(', ') }}
-
Cheers dump brings back the object. But the output as string fails with 'Array to string conversion' error. I've also tried: [code]{% set profile = currentUser.getContent() %} {% for key, value in profile %} {{ value }} {{ key }} {% endfor %}– LettieApr 23, 2015 at 11:18
-
Hmm... 'join' works fine for me on my test DB. Maybe one of the fields is being returned as an array. Possibly a matrix or table field? Apr 23, 2015 at 16:15
-
yep that is exactly what was happening. I added a check to see if any returned data was also an array and it now works fine. Thanks– LettieApr 28, 2015 at 9:25
{{ currentUser.getContent()|inspect }}