College of Education and Human Development wordmark.

News feed macro (deprecated)

Note: This is no longer the preferred way to handle news feeds. See see the updated method here.

The news feed macro is very similar to the events feed macro, except it takes different parameters.

Step one: import the macro

{% import "macros/news-feed.html" as newsfeed %}

(See information about the loader above.)

Step two: Call the macro inside a bottom_js block


{% block bottom_js %}{{ parent() }}
    {{ newsfeed.news_feed_js("category/alumni-educational-psychology/feed/") }}
{% endblock %}

        

By default, news_feed_js renders the news stories in an element with an id of "news-container". The loader creates that by default.

Once you have the loader set up, you might only need to pass in the path to the feed on the news site as shown above. The macro defaults to using the news site for news feeds. The feed we're pulling in above is http://news.cehd.umn.edu/category/alumni-educational-psychology/feed/. The macro knows to use http://news.cehd.umn.edu/, so we just have to provide the rest of the information. Thus, we pass in category/alumni-educational-psychology/feed/.

To recap:

  1. Set up your loader.
  2. Call the news_feed_js macro and pass in the path to the feed.

Calling macro with all parameters

Note: The news macro params are in a different order than the events macro. Future versions will be more consistent.


{% block bottom_js %}{{ parent() }}
{# The call to parent() above is *very* important #}
{{ newsfeed.news_feed_js(
    "category/alumni-educational-psychology/feed/", {# The path to the feed for a category #}
    "#news-container", {# The ID of the element where the stories will go #}
    "special-template.html", {# The name of the Nunjucks template #}
    2, {# The number of stories you want to display #}
    "http://news.cehd.umn.edu/", {# The url of the Wordpress site that has the feed #}
    "More news", {# The text for the "More news" link #}
    "/assets/dist/views/cehd/news" {# The path to the directory for the Nunjucks template above #}
) }}
{% endblock %}
            

The table below lists out all the parameters.

news_feed_js macro parameters
OrderParameterDescriptionDefault
firstFeed pathThe path to the RSS feed, e.g., category/alumni-educational-psychology/feed/None (required)
secondTarget element selectorA JQuery selector for the element where the news stories should be rendered#news-container
thirdNunjucks template nameThe name of the Nunjucks template used to render the eventsindex.html
fourthlimitThe number of stories to retrieve3
fifthNews feed base urlThe url for the site with the news feedhttp://news.cehd.umn.edu/
sixthmore news textThe text for the link for more newsMore news
seventhtemplate pathThe path to the Nunjucks template in the public directory/assets/dist/views/cehd/newsfeeds/

Nunjucks is a JavaScript template engine that has a syntax almost identical to Twig.