Applying a filter to specific sections of a Table of Contents?

108 weergaven
Naar het eerste ongelezen bericht

si

ongelezen,
20 jan 2020, 09:08:2420-01-2020
aan tiddl...@googlegroups.com
Hi folks.

How could you exclude all tiddlers with a certain tag from a Table-of-Contents, but only within a specific sub-section of the hierarchy?

For example, say that I have a the following table of contents:
  • Section1
    • Subitem
    • Subitem
  • Section2
    • Subitem
    • Subitem
  • Section3
    • Subitem
    • Subitem
How could I apply a filter to the macro that excludes all tiddlers with the tag "spam", but only apply it to the descendants of "Section2"?

I have tried a couple of things so far:

First I tried creating separate Table-of-Contents macros for each Section:

<div class="tc-table-of-contents">

<
<toc-selective-expandable 'Section1Tag'>>
<
<toc-selective-expandable 'Section2Tag' sort:"!tag[spam]">>
<
<toc-selective-expandable 'Section3Tag'>>

</div>

This works but puts a blank line between each section in the TOC. Maybe I'm being nitpicky but it makes the TOC look much uglier than it needs to and takes up an impractical amount of space when you have a lot of sections.

I have also tried using the following:

<div class="tc-table-of-contents">

<
<toc-selective-expandable 'TableOfContents' sort:"!tag{!!exclude-tag}">>

</div>

And then adding the field "exclude-tag=spam" to the "Section2" tiddler. This didn't work at all.

Does anyone know of a tidy way to do this?

Thanks a lot for your help. Si

Mark S.

ongelezen,
20 jan 2020, 13:33:4620-01-2020
aan TiddlyWiki
You can use the sort attribute to insert whole filter runs. However, the syntax will look lopsided:

<<toc-selective-expandable 'Section' sort:"sort[title]]+[!tag[spam]">>

Notice that the brackets are not balanced. Basically the macro is providing the final, right-hand square bracket. You need to provide sort criteria because you're over-riding the default.

This seemed to work in my tests. Topmost elements were tagged with "Section" so that they all hung together.

Good luck!

si

ongelezen,
21 jan 2020, 10:49:1721-01-2020
aan TiddlyWiki
Thank you Mark, that works perfectly, but I have realized that it is less adaptable than I initially thought.

I have tried adapting it to filter for only tiddlers tagged with "spam".

I first tried the following with the field "tag-filter=spam" in the section I want to filter:

<<toc-selective-expandable 'Section' sort:"sort[title]]+[tag{!!tag-filter}">>

The problem is that in other sections without a "tag-filter" field the filter becomes "[sort[title]]+[tag[]]" which returns nothing.

I've spent the last hour trying to figure out another way of doing it to no avail. Can you see a way to do this?

Thanks again for your help.

Mark S.

ongelezen,
21 jan 2020, 11:10:2021-01-2020
aan TiddlyWiki
!!tag-filter will use the tag-filter field of the tiddler from which the TOC macro is launched.

It's unclear where you want the tag-filter field to be coming from.

It seems like you want a tiddler to have a tag-filter field AND be marked "spam", which doesn't quite make sense to me.

Sometimes it helps to explain the big picture of what you want to do, rather than look narrowly at a particular technological solution.

Good luck!

si

ongelezen,
21 jan 2020, 13:50:3221-01-2020
aan TiddlyWiki
Hi Mark.

Sorry I realize that I had made my post more convoluted than it needed to be.

What I want to do is apply a filter to only a specific tiddler and its descendants within a TOC. Any tiddlers higher up in the hierarchy should not be subject to the filter.

By adapting your solution I am able to do this for a filter that excludes certain tags, but not for a filter that returns only tiddlers with a certain tag.

Thank you for your patience. Si

TonyM

ongelezen,
21 jan 2020, 16:40:2621-01-2020
aan TiddlyWiki
Si,

I opened this thread to introduce the idea of building your own TOC macros when more detailed customisation I required.

I have looked at a sophisticated solution to similar requirements to your own, if I can I will add it to the above thread.

This would be my design approach
  • Use my own Recursive macros (not the TOC macros)
  • Permit the addition of a field in any tiddler eg tableofcontents-filter
  • Since the same tiddler could be a member of another toc I suggest this filter field be named related to the root tiddler.
  • If the field exists with a value use this as the next level filter to call "each-other-level"
  • The filters in tiddlers should decide which children to show in the next level down.
  • Remember the filter may be recursive (called over and over again) so a filter in a tiddler should perhaps define only a limited set of tiddlers.
Regards
Tony

Joshua Fontany

ongelezen,
21 jan 2020, 17:30:2821-01-2020
aan tiddl...@googlegroups.com
I think you are over-using your "semantic tags", relying on a single tag to represent 2 different relationships.

While it might make sense to have a collection of things tagged `Section2`, including things in that group that you do not want shown on a ToC built with that tag in the tree will cause headaches.

Use `SectionX` only for things you want in the ToC, and use an alternate, like `ConceptX` to tag the others. Then you can tag ConceptX with SectionX and it can be a reference index in the ToC to all the ConceptX(s). You can use filter to add or remove the SectionX tag from ConceptX to show/hide that in the ToC dynamically.

Best,

Joshua Fontany
Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten