Page 1 of 1

ListIt Extended: Trouble with category display

Posted: Sun Nov 10, 2013 11:33 pm
by 10010110
I’m having a little issue with the logic to display a list of categories with related items beneath.
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. …
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:

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>
The problem is, if the last category is empty the code is screwed up because there will be redundant closing tags due to

Code: Select all

{if $category->prevdepth > 1}
	</ul>
</div>
{/if}
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?

Re: ListIt Extended: Trouble with category display

Posted: Mon Nov 11, 2013 8:20 am
by velden
You could have a look at a Menu Manager template. It has to cope with the same 'problem'.

Main problem of course is that you open some tags conditionally but after the foreach loop you close it without conditions.

You might also have a look at foreach|@last. Don't think the Menu Manager templates use that one, but maybe you can use it.

Re: ListIt Extended: Trouble with category display

Posted: Mon Nov 11, 2013 11:17 am
by 10010110
From what I see the MenuManager also closes the last item unconditionally. That works because there can’t be empty items that are ignored/hidden but in my case there can. And when the last one is an empty category it needs to skip the closing.
I’m gonna look into the @last modifier.

Re: ListIt Extended: Trouble with category display

Posted: Tue Nov 19, 2013 7:31 pm
by Dr.CSS
It looks like you are trying to use menu manager calls in a different module other than menu which shouldn't work at all, menutext...

Re: ListIt Extended: Trouble with category display

Posted: Wed Nov 20, 2013 8:02 am
by Stikki
menutext works with LI2, so it can be migrated with MeMa