Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-01-12 19:40:32

ax
Plugin Author
From: Germany
Registered: 2009-08-19
Posts: 165

Nested categories

An unexpected behavior occurs when working with nested categories. Suppose you have these categories:

- C1
- - C2
- - - C3
- - - - C4
- - - - - C5

Now, a category list

<txp:category_list break="br" wraptag="" children="3" parent="c1" />

returns this:

C1C2C3
C4
C5
C2C3C4
C5

But when using a container tag

<txp:category_list break="br" wraptag="" children="3" parent="c1" >
    <txp:category />
</txp:category_list>

I get this list of two items only:

c1 
c2

What am I doing wrong here?

Last edited by ax (2019-01-12 19:47:02)

Offline

#2 2019-01-13 11:10:26

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Nested categories

Nothing wrong, they are just different blocks: <txp:category_list children="3" parent="c1" /> is called recursively up to the level 3. In a pseudocode

<txp:category_list children="3" parent="c1">
    the containing <txp:category_list /> itself
</txp:category_list>

Try wraptag="ul" break="li" to see how children attribute works.

In the second example there is no recursion, so only c1 and its direct children are output.

Offline

#3 2019-01-13 13:39:47

ax
Plugin Author
From: Germany
Registered: 2009-08-19
Posts: 165

Re: Nested categories

Unfortunately, this is in contradiction to the documentation of the children attribute of the txp:category_list tag, as follows:

Values: 0 (no children, i.e. only show one level below the parent) or n (show all nested categories and ‘flatten’ the list at the level n).

But when using the container tag, you get a maximum of 2 children only, no matter of the depth of nesting, and with all values of n is > 1. Only when n = 1, then suddenly all categories are listed. And with a single tag, you get a random result (from the user’s perspective).

In my opinion, the expected behaviour would be to get exactly n children categories, no more and no less.

EDIT: As suggested, I tried wraptag="ul" break="li", but now with 7 nested categories and n = 5, like so:

<txp:category_list break="li" wraptag="ul" children="5" parent="c1" />

This results in another strange output. The HTML is:

<ul class="category_list"><li><a href="https://release-demo.textpattern.co/category/c1/">C1</a><ul class="category_list"><li><a href="https://release-demo.textpattern.co/category/c2/">C2</a><ul class="category_list"><li><a href="https://release-demo.textpattern.co/category/c3/">C3</a><ul class="category_list"><li><a href="https://release-demo.textpattern.co/category/c4/">C4</a><ul class="category_list"><li><a href="https://release-demo.textpattern.co/category/c5/">C5</a></li>
<li><a href="https://release-demo.textpattern.co/category/c6/">C6</a></li>
<li><a href="https://release-demo.textpattern.co/category/c7/">C7</a></li></ul></li></ul></li></ul></li></ul></li>
<li><a href="https://release-demo.textpattern.co/category/c2/">C2</a><ul class="category_list"><li><a href="https://release-demo.textpattern.co/category/c3/">C3</a><ul class="category_list"><li><a href="https://release-demo.textpattern.co/category/c4/">C4</a><ul class="category_list"><li><a href="https://release-demo.textpattern.co/category/c5/">C5</a><ul class="category_list"><li><a href="https://release-demo.textpattern.co/category/c6/">C6</a></li>
<li><a href="https://release-demo.textpattern.co/category/c7/">C7</a></li></ul></li></ul></li></ul></li></ul></li></ul>

And the visual output is:

   C1
        C2
            C3
                C4
                    C5
                    C6
                    C7
    C2
        C3
            C4
                C5
                    C6
                    C7

Are you sure that this is the intended result?

Last edited by ax (2019-01-13 15:12:23)

Offline

#4 2019-01-13 16:59:38

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Nested categories

Yes, that’s what I would expect: going to depth 5 and then flaten the remaining children, as with children="1" at level 0. The idea is to be able to output a category tree without nesting multiple category_lists. What did you expect and what are you trying to obtain? Isn’t it rather limit attribute that you should use here?

Edit: for the record, children="0/1" act as before.

Offline

Board footer

Powered by FluxBB