Link styles of all tags based on filter

I would like to create links of all tags based on a filter.

Using the script below, I can create links to tags.

<$list filter="[tag[TableOfContents]!sort[created]]" counter="counter">
 <$list filter="[all[current]!tags[todo]]"><$link to={{!!title}}> <$view field="title"/></$link></$list>
</$list>

However, I don’t know how to create the same style similar way of official tag, i.e.

image

How should I achieve it?

Try this:

<$list filter="[tag[TableOfContents]!tag[todo]!sort[created]]">
 <<tag>>
</$list>

Notes:

  • The TWCore does not define a specific tags[...] filter operator. When a filter operator is undefined, it is handled as if the named operator is a fieldname suffix for a field:fieldname[value] filter. Thus,!tags[todo] is handled as if you wrote !field:tags[todo], which only excludes a tiddler if it has just one tag with a value of “todo” but not if it has more than one tag, such as “task todo”. To address what I believe you intended, I combined the filter logic of both $list widgets into a single filter: [tag[TableOfContents]!tag[todo]!sort[created]]
  • Instead of using <$link to={{!!title}}> <$view field="title"/></$link> to show the title of the current tiddler, use the TWCore built-in macro, <<tag>>, which defaults to showing a tag for the currentTiddler (i.e., the {{!!title}} text) that, when clicked, will show the list of all tiddlers that have that tag.

enjoy,
-e

4 Likes

Thanks. it is working now.

Thanks @EricShulman. I have another problem to use tag macro.

If the same tags appear multiple times in a tiddler, e.g.

<<tag "TableOfContents">>

<<tag "TableOfContents">>

The tag lists open multiple times.

How could I stop it?

Patient says to Doctor: “It really hurts if I do this”
Doctor says to patient: “Then don’t do it!”

No seriously;

  • In the example you give above where the tag macro is used twice in the same tiddler this is what happens.

This has being discussed before and there are work arounds

  • but could you illustrate how this comes about for you?

Why?

  • This is a result of the way the tag macro is designed, it uses a qualify macro not based on the current tiddler but the currentTag

We need a long term fix, I am looking into it, but perhaps others have an idea.

Thanks @TW_Tones.

I would like to create a table to show tags and other information which similar as macro table-dynamic in Shiraz plugin but slight different. So I decided to start from scratch.

Sure it is not a big problem as link is also working to me.

table-dynamic should already have a solution to avoid open same tags in multiple times, but I cannot understand the codes behind it.

Example to test table-dynamic in Shiraz 2.5.1 — create stylish contents in Tiddlywiki

<<table-dynamic filter:"[tag[doc]]" fields:"title tags created modified"  stateTiddler:"statetiddler-archive" class:"w-100" editButton:"no">>

@telumire has a very neat solution to the multiple-tags problem here - the key is to introduce a transclusion, e.g. as the variable in your generating list. I haven’t dived into the Shiraz code, but I suspect it accomplishes the same thing by using template transclusion.

2 Likes

When you click on a tag displayed via the <<tag>> macro, a popup is created to show the list of links to the tiddlers with that tag. This popup uses the $reveal widget which is controlled by a “state” tiddler. The name of the state tiddler is generated by using the <<qualify>> macro, which adds a “magic number” to the state tiddler title.

As described here:

“The qualify macro… returns a unique string that encodes its position within the widget tree, as identified by the stack of transcluded tiddlers that lead to that position… It is implemented using the transclusion variable.”

Normally, the transclusion variable is automatically set whenever you transclude a tiddler using {{TiddlerName}} or {{!!fieldname}} or <$transclude tiddler=.. />.

Since you are using multiple instances of <<tag "TableOfContents">> macro in the same tiddler, they all have the same value for the transclusion variable. As a result, the $reveal widgets all generate the same “magic number” for the <<qualify>> value, and thus all the popup state tiddler titles are using the same name. The result is, as you have noted, that clicking on any tag displayed with the <<tag>> macro causes the popup to be displayed for every tag with the same name.

Fortunately, there is a quick workaround that you can use to force each instance of the <<tag>> macro to generate a unique <<qualify>> value by surrounding each <<tag>> instance with a <$let> widget that manually sets the transclusion variable, like this:

<$let transclusion="1"><<tag "TableOfContents">></$let>
<$let transclusion="2"><<tag "TableOfContents">></$let>

For your particular use case, in which you are producing a table of output where each row of the table is for a different tiddler, you can set the transclusion variable to that row’s tiddler title, ensuring that any tags shown for that row have a unique popup state title. Something like this:

<$let target="doc">
<table>
<$list filter="[tag<target>]" variable="thistiddler">
   <tr>
      <td><$link to=<<thistiddler>>/></td>
      <td>
         <$list filter="[<thistiddler>get[tags]enlist-input[]] -[<target>]">
            <$let transclusion=<<thistiddler>>><<tag>></$let>
         </$list>
      </td>
   </tr>
</$list>
</table>
</$let>

enjoy,
-e

4 Likes

Very appreciate it @EricShulman. Learn a lots from here. Now I can develop a macro to show tags.