Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-03-09 12:16:00

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Making nested lists

Can’t seem to find the thread on how to use breakform/breakby/<+>/wraptag/wrapform/etc for link lists, sorry, and I don’t think my brain is in today.

I’m trying to make a nested linklist where each subcategory is headed by the link category name, and then has a list of links in that category beneath. It could be a ul/li or, in this case, dl/dt/dd because I have descriptions too.

Here’s my progress so far:

<txp:variable name="reading-cats">
    <txp:category_list type="link" parent="further-reading" break="," trim>
        <txp:category />
    </txp:category_list>
</txp:variable>

<txp:evaluate test="linklist">
    <section>
        <h3>Further reading</h3>
        <txp:linklist category='<txp:variable name="reading-cats" />' sort="category" wrapform="linkgroup">
            <dt><txp:linkdesctitle /></dt>
            <dd><txp:link_description /></dd>
        </txp:linklist>
    </section>
</txp:evaluate>

And linkgroup form:

<h4><txp:link_category /></h4>
<dl><+></dl>

My thinking was that, in the absence of breakform in the <txp:linklist /> tag (which I’m not sure would help anyway) I could use the tie fighter <+> to inject the contents of the container for every record and use the wrapform to output the subcategory heading and <dl> wrapper. But of course using <txp:link_category /> in a wrapping context means it’s out of scope.

I’ve been donkeying around with <txp:if_different> too to no avail. I’m sure I’ve solved this before on a site (though that was for categories, not linklists that have fewer attributes) so I’m probably approaching this in a really convoluted way but I can’t figure it out today. Any pointers gratefully appreciated.

Last edited by Bloke (2021-03-09 12:18:20)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2021-03-09 12:27:51

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Making nested lists

Untested

<txp:category_list type="link" parent="further-reading" break="" wraptag="dl">
<txp:category title="1" />
<dt><txp:linkdesctitle /></dt>
<dd><txp:link_description /></dd>
<txp:category_list type="link" parent='<txp:category />' exclude='<txp:category />' break="" wraptag="dl">
<dt><txp:linkdesctitle /></dt>
<dd><txp:link_description /></dd>
</txp:category_list>

Last edited by colak (2021-03-09 12:29:59)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2021-03-09 12:56:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: Making nested lists

Thanks, but doesn’t that wrap the category title in the <dl> too which is specifically what I’m trying to avoid? This is what I’m trying to achieve in HTML, in the most efficient and maintainable way possible so as new subcategories and links are added, everything just carries on working:

<h3>Further reading</h3>
<h4>Books</h4>
<dl>
<dt>Title and link</dt>
<dd>Link description</dd>
<dt>Title and link</dt>
<dd>Link description</dd>
<dt>Title and link</dt>
<dd>Link description</dd>
...
</dl>
<h4>Online resources</h4>
<dl>
<dt>Title and link</dt>
<dd>Link description</dd>
<dt>Title and link</dt>
<dd>Link description</dd>
<dt>Title and link</dt>
<dd>Link description</dd>
...
</dl>

and so forth. Or, y’know, ul/li would work. I’m after some generic approach that can be used to make a bunch of lists neatly from a single parent source, instead of having a tonne of <txp:if_different> or <txp:evaluate> calls to check if stuff exists. I feel that some combination of our wraptag/wrapform/break/breakform/breakby and tie fighter ought to be able to do it but the solution evades my puny mind.

Last edited by Bloke (2021-03-09 12:59:53)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2021-03-09 13:10:11

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Making nested lists

Bloke wrote #329166:

Thanks, but doesn’t that wrap the category title in the <dl> too which is specifically what I’m trying to avoid? This is what I’m trying to achieve in HTML, in the most efficient and maintainable way possible so as new subcategories and links are added, everything just carries on working:

<h3>Further reading</h3>...

and so forth. Or, y’know, ul/li would work. I’m after some generic approach that can be used to make a bunch of lists neatly from a single parent source, instead of having a tonne of <txp:if_different> or <txp:evaluate> calls to check if stuff exists. I feel that some combination of our wraptag/wrapform/break/breakform/breakby and tie fighter ought to be able to do it but the solution evades my puny mind.

Let’s try one step at a time. Thinking of your headings, what about this?

<txp:category_list type="link" parent="further-reading" break="" label='<txp:category title="1" />' labeltag="h4" wraptag="dl">
...
<txp:category_list type="link" parent='<txp:category />' exclude='<txp:category />' label='<txp:category title="1" />' labeltag="h4" break="" wraptag="dl">

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2021-03-09 13:10:29

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

Re: Making nested lists

Bloke wrote #329166:

I feel that some combination of our wraptag/wrapform/break/breakform/breakby and tie fighter ought to be able to do it

It would, but custom breakby is available only in <txp:article[_custom] />. Here you’ll need to pass through the usual ugly if_first/last/different dance, I’m afraid. Unless you don’t mind a db query per category, of course.

Offline

#6 2021-03-09 13:30:43

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: Making nested lists

etc wrote #329168:

It would, but custom breakby is available only in <txp:article[_custom] />. Here you’ll need to pass through the usual ugly if_first/last/different dance, I’m afraid.

Drat. I thought I was missing something obvious, since it worked for articles and categories.

Okay, no worries. Thanks for the sanity check. I’ll resort to the first/last/different dance, but if we could put this concept on the tag wish list for future, that’d be ace.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2021-03-09 13:55:58

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

Re: Making nested lists

Bloke wrote #329170:

if we could put this concept on the tag wish list for future, that’d be ace.

I don’t see a way to make it global with our current lists processing. We could duplicate the code for all content types, but my hope is to rather use one function to handle them all.

That’s how it would work then:

...
        <txp:linklist category='<txp:variable name="reading-cats" />' sort="category" breakby="<txp:link_category />" breakform="linkgroup">
            <dt><txp:linkdesctitle /></dt>
            <dd><txp:link_description /></dd>
        </txp:linklist>
...

Offline

#8 2021-03-09 14:59:28

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: Making nested lists

etc wrote #329171:

That’s how it would work then:

That’s exactly how I was hoping it would work in my tests earlier but I was thwarted by lack of breakby! So I tried wrapform instead and was hit with the out-of-context issues, which makes sense as the wrap isn’t applied until after the tag and its container is processed, at which point any inner context is lost.

The only way I thought to do that and maintain context would be like this (untested):

<txp:linklist category='<txp:variable name="reading-cats" />' sort="category" wrapform="linkgroup">
    <txp:variable name="linkcat"><txp:link_category title /></txp:variable>
    <dt><txp:linkdesctitle /></dt>
    <dd><txp:link_description /></dd>
</txp:linklist>

And in linkgroup:

<h4><txp:variable name="linkcat" /></h4>
<dl><+></dl>

Not super pretty, and it reassigns the category each time which is a bit of a waste of processor cycles (not sure if <txp:if_different> can help here) but it’s still neater than the if_last/first/different dance.

Last edited by Bloke (2021-03-09 15:01:54)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2021-03-09 15:18:06

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

Re: Making nested lists

Not sure this would work as intended, since wrapform is applied at the very end, so you would get the whole linklist wrapped into it:

<h4>Last cat name</h4>
<dl>
    <dt>Title 1</dt>
    <dd>Description 1</dd>
    ...
    <dt>Title n</dt>
    <dd>Description n</dd>
</dl>

Offline

#10 2021-03-09 15:19:20

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: Making nested lists

etc wrote #329175:

Not sure this would work as intended, since wrapform is applied at the very end, so you would get the whole linklist wrapped into it.

Yeah just found that out. Darn!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2021-03-09 15:26:48

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: Making nested lists

This is compounded by <txp:if_first_link> only firing on the first link of the entire tag, not the first link of each category, since breakby can’t be used to divert to a breakform.

Looks like the only way to do it is to iterate over each subcategory with its own linklist tag, as colak proposed.

Last edited by Bloke (2021-03-09 15:28:06)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#12 2021-03-09 15:35:12

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: Making nested lists

For the record, this code works, albeit sub-optimally:

<txp:category_list type="link" parent="further-reading" exclude="further-reading" break="" label="Further reading" labeltag="h3">
    <h4><txp:category title /></h4>
    <txp:linklist category='<txp:category />' break="" wraptag="dl">
        <dt><txp:linkdesctitle /></dt>
        <dd><txp:link_description /></dd>
    </txp:linklist>
</txp:category_list>

Thank you for everyone’s assistance. Looking forward to the day this can be done in line with the superior attributes that article/category list tags support.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB