I'm hoping someone can suggest an elegant solution to this. I sometimes need to have the result that a channel:entries loop inside a channel:categories loop can provide. A simple example would be:
<ul>
{exp:channel:categories channel="main" style="linear"}
<li>{category_name}
<ul>
{exp:channel:entries channel="main" category="{category_id}"}
<li>{title}</li>
{/exp:channel:entries}
</ul>
</li>
{/exp:channel:categories}
</ul>
This sort of approach allows for categories to be added/removed on the fly without having to alter the template, but I am aware that such nesting can be bad for performance. What is the better way to do this?
One user has suggested using the category_archive tag but since that tag can only grab title or url_title content from entries it would not permit something like this:
<table>
{exp:channel:categories channel="courses" style="linear"}
<tr><th colspan="5">{category_name}</th></tr>
<tr>
<th>Course Title</th>
<th>Course ID</th>
<th># Days</th>
<th>Description</th>
<th>Price</th>
</tr>
{exp:channel:entries channel="courses" category="{category_id}"}
<tr>
<td>{title}</td>
<td>{course_code}</td>
<td>{course_duration}</td>
<td>{course_blurb}</td>
<td>{price}</td>
</tr>
{/exp:channel:entries}
{/exp:channel:categories}
</table>
Please note that in the above example {course_code}, {course_duration}, {course_blurb} and {price} are all existing entry fields.