ListIt Extended: Trouble with category display
Posted: Sun Nov 10, 2013 11:33 pm
I’m having a little issue with the logic to display a list of categories with related items beneath.
What I want is this:
The set-up is simple: I have one level of categories (no sub categories so far) and items associated to these (but not necessarily, can also be empty).
Now, my template looks like this:
The problem is, if the last category is empty the code is screwed up because there will be redundant closing tags due to
and the closing tags after the loop.
If I remove the ones after the loop then the last item isn’t closed properly (if it’s not empty).
I can’t figure this out. What’s the solution to this dilemma?
What I want is this:
Code: Select all
<div class="category">
<h3>[category heading]</h3>
<ul>
<li>[category item]</li>
<li>[category item]</li>
…
</ul>
</div>
<div class="category">
…
</div>
<div class="category">
…
</div>
… etc. …
Now, my template looks like this:
Code: Select all
<div class="praesidium">
{foreach from=$categories item=category}
{if $category->depth == 1}
{if $category->prevdepth > 1}
</ul>
</div>
{/if}
{if !count($category->items)}
{continue}
{/if}
<div class="category {$category->alias}">
<h3>{$category->menutext}</h3>
<ul>
{else}
<li>{$category->menutext|cms_escape}, {$category->depth}</li>
{/if}
{/foreach}
</ul>
</div>
</div>
Code: Select all
{if $category->prevdepth > 1}
</ul>
</div>
{/if}
If I remove the ones after the loop then the last item isn’t closed properly (if it’s not empty).
I can’t figure this out. What’s the solution to this dilemma?