0

i have a array like this and want to get the content.

Array
(
    [0] => Array
        (
            [0] => 1
            [id] => 1
            [1] => Testnews
            [title] => Testnews
            [2] => Dies ist eine kleine <strong>Testnews!</strong>
            [text] => Dies ist eine kleine <strong>Testnews!</strong>
            [3] => 1
            [type] => 1
            [4] => 1
            [timestamp] => 1
            [5] => 0
            [status] => 0
        )

)

I tried the following:

                    {% for latest_news in news %}
                        {% for id, title in latest_news %}
                            id : {{ id }}
                            title : {{ title }}
                        {% endfor %}
                    {% endfor %}

That works, but i don't think this is the right way to do this.

How should it look like?

2 Answers 2

2

I just found the right and easiest solution:

                {% for latest_news in news %}
                     id : {{ latest_news.id }}                      
                     title : {{ latest_news.title }}                      
                {% endfor %}
Sign up to request clarification or add additional context in comments.

2 Comments

Mis-read your array (ignore my answer). Yeah, that's definiately the way forward.
I forgot that you can access a array directly if you add the dot. But thanks anyways. Maybe this hels anyone ^^
0

I'd say that's right. You could also do:

{% for latest_news in news %}
    {% for news_item in latest_news %}
         id: {{ news_item.id }}
         title: {{ news_item.title }}
    {% endfor %}
{% endfor %}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.