Ad

Twig Template JSON To Something Readable

- 1 answer

I use october CMS and trying to extend some futures on one of the modules.

I have settings column in my DB, that have several fields. But when user type something in this fields goes to DB like JSON : {"about":"dsadasdas","nickname":"bojko"} or {"nickname":"qnica","about":"test"}

When i try to dispalay this in profile page {{ueuser.user.settings}} first gives me this error

An exception has been thrown during the rendering of a template ("Array to string conversion").

I read a lot and add {{ueuser.user.settings|join(',')}}

Now on display shows enter image description here or enter image description here

But i want to add some style To show something like Nickname: qnica About: test .... and etc.

How can i do this? Here is a {{dump(ueuser.user.settings)}}enter image description here

Ad

Answer

You should check https://twig.symfony.com/doc/3.x/tags/for.html

{# example #}
<ul>
    {% for key, value in ueuser.user.settings %}
        <li>{{ key }}: {{ value }}</li>
    {% endfor %}
</ul>
Ad
source: stackoverflow.com
Ad