1

The code I have works, but I don't understand why and am seeking an explanation rather than a fix.

I have a template which displays a list of news articles. The channel is called news. I also have another channel called news_overview which is used to create an "intro" page to my list of news articles (which belong in the news channel).

So my template is as follows:

{exp:channel:entries channel="news_overview" limit="1"}
   <!-- Display banner and other details from `news_overview` channel -->
{/exp:channel:entries}


{exp:channel:entries channel='news' orderby='date' sort='desc' limit="9" paginate="bottom"}

  <!-- Display each article's title and a link to read it -->
  <h1>{title}</h1>
  <p><a href="{url_title_path='news'}">Read article</a></p>

{/exp:channel:entries}

My news entries are categorised.

When I go to a URL (/news) it loads up the template above and everything works.

However when I go to a category based URL such as /news/category/events it loads the appropriate articles....but not the information from news_overview. In other words, it loads the appropriate list of news articles (which are categorised as "events") but is missing the banner and intro text from news_overview at the top of the template - nothing is output there.

I managed to fix this by adding dynamic="no" to the first channel entry tag:

{exp:channel:entries channel="news_overview" limit="1" dynamic="no"}

This fixed the problem. But I don't understand why?

According to the documentation

There are times, however, where you do not want the parameters affected by what the URL contains. To override the dynamic nature of the channel tag, use dynamic="no".

Why does the URL affect loading data in this way? My understanding of my initial channel entries tag is that it's just asking for 1 entry from news_overview. Given that this is the same on every page, and isn't even from the news channel, why does it affect it in this way? I understand why it affects the news entries that are found in the query...because the categories are tied to news, but not news_overview.

1 Answer 1

1

A helpful example of dynamic="no": https://docs.expressionengine.com/latest/how_to/building_a_simple_news_site.html#a-dynamic-duo

also see: https://docs.expressionengine.com/latest/urls/url_structure.html#viewing-your-site

Your /news page is showing multiple entries because there's no valid URL Title in the URL to limit the entries displayed, so everything is displayed (limited by the other channel entries parameters, like channel, status, etc...).

But on the category limited url (/news/category/events) the channel entries tag will look for all entries matching that category. Using the dynamic="no" parameter overrides that and ignores the URL.

So use dynamic="no" any time you want to get a specific set of entries based on that channel entry tag parameters, regardless of where you are.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.