TheCadien / SuluNewsBundle

Simple News Bundle for Sulu 2 CMS
MIT License
14 stars 12 forks source link

Type "news_selection" not available #28

Closed kleffsche closed 1 year ago

kleffsche commented 1 year ago

So I managed to install this bundle with Sulu 2.5 and Symfony 6 but when I try to select news (type news_selection)on a page, for example in homepage.xml like this:

<property name="news" type="news_selection" mandatory="true">
    <params>
        <param name="min" value="1"/>
    </params>
</property>

the page won't load anymore.

When I try to load news in a block:

<type name="news">
    <properties>
        <property name="news-select" type="news_selection" mandatory="true">
            <params>
                <param name="min" value="1"/>
            </params>
        </property>
    </properties>
</type>

the page loads but I got this error:

image
TheCadien commented 1 year ago

Thanks for reporting, the news_selection will be fixed in the next release with the Sulu 2.5 and Symfony Update again.

Bildschirm­foto 2022-11-09 um 23 30 02
TheCadien commented 1 year ago

I also added a twig extension so that the news can be easily loaded in a frontend. Call the news from the list of "news_selection" with sulu_resolve_news(id).

kleffsche commented 1 year ago

That works very well, I just have to figure out how to get the items from the news, or better, from the resolved news (sulu_resolve_news), but I guess this twig extension makes it a lot easier.

A small example, how I get the data in a twig view:

{% for newsItem in content.news %}
     {% set news = sulu_resolve_news(newsItem.id) %}
     {% if news.header.id|default %}
         {% set image = sulu_resolve_media(news.header.id, app.request.locale) %}
             <img src="{{ image.thumbnails['2560x550'] }}">
     {% endif %}
{% endfor %}

I think that's the right way to do it with data from a news_selection, isn't it?

Thank you, again, for your help and this very useful bundle. :+1

P.S. a small code example for a twig view in the README docs would be nice. Just saying.