[TW5] Filter using current tiddler's title?

2,732 views
Skip to first unread message

Devin Baillie

unread,
Oct 31, 2015, 1:56:27 AM10/31/15
to TiddlyWiki
I'm trying to make a template tiddler to display all the tasks associated with the current project.  If I have a tiddler named "TestProject" and two tiddlers tagged with "TestProject", "TestTask1" and "TestTask2", I'd like to be able to create a list of the tasks in the current project.

If I use

<$list filter="[tag[TestProject]]">

</$list>

then I get the expected output

TestTask1
TestTask2
 

I searched and found this thread, which suggested a few alternatives that didn't work:


 <$list filter="[tag[$(title)$]]">

</$list>

and

<$list filter="[tag<currentTiddler>]">

</$list>

and

<$list filter="[tag{!!title}]">

</$list>

all give nothing.

Any thoughts on how to get this to work?

Thanks in advance!

Matabele

unread,
Oct 31, 2015, 4:04:55 AM10/31/15
to tiddl...@googlegroups.com
Hi

There's a special tagging[] operator for this: [all[current]tagging[]], will list all tiddlers tagged with the title of the current tiddler.

But any of these should work:

<$list filter="[tag{!!title}]"/>
<$list filter="[{!!title}tagging[]]"/>
<$list filter="[all[current]tagging[]]"/>
<$list filter="[tag<currentTiddler>]"/>
<$list filter="[<currentTiddler>tagging[]]"/>
<$list filter="[<currentTiddler>listed[tags]]"/>
<$list filter="[{!!title}listed[tags]]"/>

Don't know why you're not getting the same result.

regards

Devin Baillie

unread,
Oct 31, 2015, 9:33:40 AM10/31/15
to TiddlyWiki
Interesting.  These all seem to work, but not in the "Preview" panel, which I was using to try out my filters.  I guess I'd better file a bug report. :-)

Thanks,
Devin

Antaeus Feldspar

unread,
Oct 31, 2015, 9:48:54 AM10/31/15
to TiddlyWiki
| I searched and found this thread, which suggested a few alternatives that didn't work:


| <$list filter="[tag[$(title)$]]">

| </$list>

| and

| <$list filter="[tag<currentTiddler>]">

| </$list>

| and

| <$list filter="[tag{!!title}]">

| </$list>

| all give nothing.

I think I may have figured out the problem. If you take that middle form, where the filter is "[tag<currentTiddler>]", but you don't leave at least one line (even an empty one) between the opening and closing <$list> tags, the list will render nothing. If your closing tag is on the very next line from the opening tag, that may be the cause.

Matabele

unread,
Oct 31, 2015, 9:50:32 AM10/31/15
to TiddlyWiki
Hi

They wouldn't, they all filter on the title of the current tiddler. When you enter the preview panel, the current tiddler becomes '$:/AdvancedSearch'.

regards

Devin Baillie

unread,
Oct 31, 2015, 9:54:16 AM10/31/15
to TiddlyWiki
Good to know.  I won't rely on it in the future.

Thanks.

Matabele

unread,
Oct 31, 2015, 9:57:50 AM10/31/15
to TiddlyWiki
Hi

It's a useful tool, especially for complex filter expressions. Substitute a hard link (tiddler title) to test the filter, then replace this with the {{!!title}} reference for use.

regards

Devin Baillie

unread,
Oct 31, 2015, 1:15:06 PM10/31/15
to TiddlyWiki
Good thought.  I'll do that from now on, thanks so much for your help.

Antaeus Feldspar

unread,
Oct 31, 2015, 3:08:47 PM10/31/15
to TiddlyWiki
| They wouldn't, they all filter on the title of the current tiddler. When you enter the preview panel, the current tiddler becomes '$:/AdvancedSearch'.

Actually, I think Devin may mean the preview panel that's part of the Edit Template. If you're editing tiddler "Foo" and you click the "show preview" button, you'll see a pane where the content is rendered with "Draft of 'Foo'" as the currentTiddler.

I mention this because I find this irksome too when I want to see the effect of changes right away, and I've been working on a filter expression which would return "Foo" for both "Foo" and "Draft of 'Foo'". I think I have a final version here (I've put each of the three component runs on its own line for clarity:

[title<currentTiddler>]
-[prefix[Draft of ']suffix[']]
[title<currentTiddler>removeprefix[Draft of ']removesuffix[']]

(Obviously, this screams out to be made a macro to avoid typing all that out repeatedly.)

For Devin's purposes, a fourth run appended to the expression, "+[tagging[]]", turns the input "Foo" into the list of tiddlers tagged with "Foo".

Erwan

unread,
Oct 31, 2015, 7:53:40 PM10/31/15
to tiddl...@googlegroups.com

On 31/10/15 19:08, Antaeus Feldspar wrote:
> I mention this because I find this irksome too when I want to see the effect of changes right away, and I've been working on a filter expression which would return "Foo" for both "Foo" and "Draft of 'Foo'". I think I have a final version here (I've put each of the three component runs on its own line for clarity:
>
> [title<currentTiddler>]
> -[prefix[Draft of ']suffix[']]
> [title<currentTiddler>removeprefix[Draft of ']removesuffix[']]
>
> (Obviously, this screams out to be made a macro to avoid typing all that out repeatedly.)

Hi Antaeus,

I also sometimes use this, I think you can make it a bit simpler by
using the fact that a tiddler in edit mode has a field 'draft.of':

\define filterNonDraftTitle() [all[current]get[draft.of]]
[all[current]!has[draft.of]]

I use it like this:

<$list filter=<<filterNonDraftTitle>> >
<$text text=<<currentTiddler>> />
</$list>

It's also useful for creating a button which works for both the view
toolbar and the edit toolbar.

Erwan

Matabele

unread,
Nov 1, 2015, 12:45:40 AM11/1/15
to tiddl...@googlegroups.com
Hi

I tried this -- it doesn't work :-(

I created a global macro:

\define currentTitle()
<$list filter="[<storyTiddler>get[draft.of]] [<storyTiddler>!has[draft.of]]">

</$list>
\end

The result of a simple macrocall is as expected in both view and edit mode: 

<<currentTitle>>

However, when I try this, there is no output in either view or edit mode:

<$list filter="[tag<currentTitle>]"/>

<$list filter="[
<currentTitle>tagging[]]"/>

<$list filter="[
<currentTitle>listed[tags]]"/>

Anyone know why?

regards

Eric Shulman

unread,
Nov 1, 2015, 2:25:57 AM11/1/15
to TiddlyWiki
On Saturday, October 31, 2015 at 9:45:40 PM UTC-7, Matabele wrote:
I tried this -- it doesn't work :-(
I created a global macro:
\define currentTitle()
<$list filter="[<storyTiddler>get[draft.of]] [<storyTiddler>!has[draft.of]]">

</$list>
\end

The result of a simple macrocall is as expected in both view and edit mode: 
<<currentTitle>>

However, when I try this, there is no output in either view or edit mode:

<$list filter="[tag<currentTitle>]"/>
<$list filter="[
<currentTitle>tagging[]]"/>
<$list filter="[
<currentTitle>listed[tags]]"/>

Anyone know why?

There is a widespread and common misperception about macros.  Specifically, because they have a parameter passing syntax, they *look* somewhat like the function syntax in other languages.  As a result, there is an expectation that they *work* like functions do, and can "compute and return" a resulting value. However.... macros don't actually do any computation other than simple *text substitution* to replace any instances of $paramname$ and $(variablename)$ within the macro content and then return that modified content for further handling.

What happens with that result depends on where it is used:

* If the macro result is returned directly into a wiki context (i.e. <<macroname ...>> is embedded directly in wikitext), then the macro's output will be parsed ("wikified") and any <$widgets> and/or <<macroname>> references are then processed in turn.
* If a macro result is used as a widget parameter (e.g., <$widget paramname=<<macroname>>...></$widget>) or as a reference within a filter (e.g., [tag<macroname>]), then the macro's output is *not* parsed, and is simply used as literal text by the widget or filter handler.

The confusion arises because of this different contextual handling for the macro results...

In your example, the output of the "currentTitle" macro, which has no parameters, is always, literally:
<$list filter="[<storyTiddler>get[draft.of]] [<storyTiddler>!has[draft.of]]">

</$list>

In the first context, where you parse and render the output of <<currentTitle>>, the <$list> widget is invoked, and the expected output is shown.  However, in the second context, where you use [...<currentTitle>...] within a filter, the output of the macro is *not* parsed, so the filter is, literally:
<$list filter="[tag[<$list filter="[<storyTiddler>get[draft.of]] [<storyTiddler>!has[draft.of]]">

</$list>]]"/>

One possible work-around is to first use the <$set> widget with the filter="..." param to get the actual filter result (the desired tag name), and then use that variable within the subsequent list filter (to list tiddlers that are tagged with that name), like this:
<$set name="target" filter="[<storyTiddler>get[draft.of]] [<storyTiddler>!has[draft.of]]">
<$list filter="[tag
<target>]"/>
</$set>

I hope this explanation helps,

enjoy,
-e

Matabele

unread,
Nov 1, 2015, 4:01:02 AM11/1/15
to TiddlyWiki
Hi Eric

Many thanks for the explanation.

Now, I create a global macro:

\define tagged()

<$set name="target" filter="[<storyTiddler>get[draft.of]] [<storyTiddler>!has[draft.of]]">
<$list filter="[<target>tagging[]]"/>
</$set>
\end

And there is no output when called :-(

<<tagged>>

Why, in this case, is the macro code not wikified?

regards
Reply all
Reply to author
Forward
0 new messages