Printing the results of a fliter

87 views
Skip to first unread message

Mark Green

unread,
Jun 27, 2020, 6:45:11 PM6/27/20
to TiddlyWiki
I'm trying to use the if-then options in a filter to create a transcludable template which will add a list of standard messages to a tiddler if it has certain tags.

However, there doesn't seem to be a way to just print the result of a filter; it has to be listed instead. Also, the result of the if-then seems to be made into a link.

How can you just output the result of an if/then filter?

Jake

unread,
Jun 27, 2020, 7:01:03 PM6/27/20
to tiddl...@googlegroups.com
Was thinking about a very close problem. I think you'd be advised with a better solution, since I'm a total newbie, but try this one:

Filtered List Variable Assignment

This form of the set variable widget evaluates the filter and assigns the result to the variable as a space-separated list (using double square brackets for titles containing spaces).

<$set name="myVariable" filter="[tag[HelloThere]]">
<$text text=<<myVariable>>/>
</$set>


For if/then filter - just insert your filter in the first string.

TW Tones

unread,
Jun 27, 2020, 7:56:52 PM6/27/20
to TiddlyWiki
Mark,

When you say print are you talking to a printer out just output?

<$list filter="[tag[HelloThere]]" variable=myVariable>
   <$transclude tiddler=<
<myVariable>> mode=block><br>
</$list>
Try this on Tiddlywiki.com

Can be simplified to...
<$list filter="[tag[HelloThere]]">
   <$transclude mode=block>
<br>
</$list>

Do not under estimate listing its the key method of handling any set, including sets of zero or one. And tiddler handling.

Regards
Tony

Mark Green

unread,
Jun 27, 2020, 8:57:01 PM6/27/20
to TiddlyWiki
I mean just output, but these are still transcluding another tiddler.

What I want to do is to make a template that I can include in a tiddler which will, for example
- If the current tiddler has the "Obsolete" tag, add the sentence "This function is obsolete."
- If the current tiddler has the "Unsafe" tag, add the sentence "This function is unsafe and should not be reused."

With these being independent choices, so that if it has both, both are displayed.

This template can then be placed on multiple pages to generate standard warnings.

Mat

unread,
Jun 28, 2020, 4:12:32 AM6/28/20
to TiddlyWiki
Mark Green wrote:
This template can then be placed on multiple pages to generate standard warnings.

(When you say "pages" I assume you mean tiddlers, right?) 

Anyway, you can make a conditional viewtemplates like so:

tags: $:/tags/ViewTemplate
text
:
<$list filter="[all[current]tag[Obsolete]]">
This function is obsolete.
</$list>
<$list filter="[all[current]tag[Unsafe]]">
This function is unsafe.
</
$list>

<:-)

Mark Green

unread,
Jun 29, 2020, 3:12:20 PM6/29/20
to TiddlyWiki
Thanks! That's great!

There is however a small problem that's come up as well. I'd like to display the warnings - all of them if possible - in a table.So I tried this:

<$list filter="[all[current]tag[Obsolete]]">
| !Obsolete | This function is obsolete. |
</$list>
<$list filter="[all[current]tag[Unsafe]]">
| !Unsafe | This function is unsafe. |
</
$list>

The problem is that if I write it like this, it doesn't put a newline after each line of the table when rendering the list, so it isn't displayed as a table.

However, if I insert a blank line before each of the table entries, then it ends the entire paragraph before each table line and it displays as a series of one-line tables instead of a single one.

Using HTML <br> divides the text into lines, but the | | |s are then not recognized as a table. There seems not to be an option for "I want a newline here for the purpose of your parser, but that might not mean a newline in the output". Can this be done?

Eric Shulman

unread,
Jun 29, 2020, 3:35:02 PM6/29/20
to TiddlyWiki
TiddlyWiki table formatting (using "|foo|bar|" syntax) works well enough for simple tables, but doesn't really handle generated table output where there is intervening syntax in between each row (like the $list widgets in your example)

The best way to work around the limitations is use HTML syntax, like this:
<table>
<$list filter="[all[current]tag[Obsolete]]">
<tr><th> Obsolete </th><td> This function is obsolete. </td></tr>
</$list> 
<$list filter="[all[current]tag[Unsafe]]">
<tr><th> Unsafe </th><td> This function is unsafe. </td></tr>
</$list>
</table>

enjoy,
-e
Reply all
Reply to author
Forward
0 new messages