[TW5] Computing and using filters within macros

110 views
Skip to first unread message

Xavier Cazin

unread,
Jan 24, 2017, 12:58:55 PM1/24/17
to tiddl...@googlegroups.com
Hi everyone,

Recently, I gave up on the code below, because I thought I missed something regarding parametrized macro calls, but in an answer today to Tony Grosinger, Jeremy said something about wikified text that can't be used as a setting that rang a bell.

My problem was merely to compute a filter in a <$list/> widget inside a macro and then use the computed filter in another macro:
<!-- Macro to compute the filter -->
\define myfilter(namespace:"mp:") <$list filter="[prefix[$namespace$]] +[field:text[Yes]] +[removeprefix[$namespace$]]"
emptyMessage="No path set!">tag[<<currentTiddler>>]</$list> \end

<!-- Macro to display the filtered tiddlers -->
\define mytiddlers(filter) <$list filter="[$filter$]"> </$list> \end

I was hoping to display a list of tiddlers that matched the filter computed in the myfilter macro,
but <$macrocall $name="mytiddlers" filter=<<myfilter>> /> keeps returning
the (correctly) instanciated code of mytiddlers,
say <$list filter="[tag[english]tag[power user]]"> </$list>,
instead of the actual list of tiddlers.


Is there a way solve this kind of issue?
Thanks in advance!
-- Xavier Cazin

Jed Carty

unread,
Jan 24, 2017, 1:05:03 PM1/24/17
to TiddlyWiki
I am not sure the exact code for it, but it sounds like you want to use something like the set widget and give it a filter.

Tobias Beer

unread,
Jan 24, 2017, 1:20:04 PM1/24/17
to TiddlyWiki
Hi Xavier,

Can you please rewind entirely and
describe what you want to list and
what you presume the filter for that would be, statically,
and what part of that filter you want to be dynamic / parameterizable via macro
and what roles "namespaces" are playing in all this?

Best wishes,

Tobias. 

Xavier Cazin

unread,
Jan 24, 2017, 2:09:41 PM1/24/17
to tiddl...@googlegroups.com
Hi Tobias,

Well, I wanted to make a plugin that allows multiple reading paths for a same tutorial, based on preferences set by the user. For instance, when the user sets the three config tiddlers "mp:english", "mp:power user" and "mp:android 5", the sections used for the tutorial would be those which bear the three tags "english", "power user" and "android 5".

Hence my wish to:
  1. compute a filter that reflects the user config (for instance "[tag[english]tag[power user]]"). There would be more information in this filter, like the wanted location inside the tutorial.
  2. Use this filter to  get the list of the tiddlers that are relevant when building the tutorial.

Here are my two tentative macros again. namespace is nothing more than a way to extract tags from configuration tiddler titles:

<!-- Macro to compute the filter -->
\define myfilter(namespace:"mp:") <$list filter="[prefix[$namespace$]] +[field:text[Yes]] +[removeprefix[$namespace$]]"
emptyMessage="No path set!">tag[<<currentTiddler>>]</$list> \end

<!-- Macro to display the filtered tiddlers -->
\define mytiddlers(filter) <$list filter="[$filter$]"> </$list> \end

Jed's suggestion to use <$set/> rather than <$list/> sounds like a better approach but then I have trouble figuring how I could build my filter out of any number of settings.

If you see light in there, that would be terrific!

-- Xavier Cazin

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/cf3d8ba3-fa82-4b4f-a401-ac979b7ea526%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Tobias Beer

unread,
Jan 24, 2017, 3:42:15 PM1/24/17
to TiddlyWiki
Hi Xavier,

Assuming you've managed to store the tags selected by the user
in some state tiddler's text, then you can use tobibeer/contains
to get all tiddlers that have the same titles from that list as tags, e.g.:

This would be the example you might want to look at:

In your case it would look something like:

<$vars selected={{$:/states/selected-tags}}>
<$list filter="[contains:tags $all<selected>sort[title]]">
...do your thing...
</$list>
</$vars>

Try this example directly on http://tobibeer.github.io/tw5-plugins to see an example:

<$vars selected="Filters Plugins">
<dl>
<$list filter="[contains:tags $all
<selected>sort[title]]">
<dt><$link><$view field="title"/></$link></dt>
<dd>''field:'' {{!!tags}}</dd>
</$list>
</dl>
</$vars>

Best wishes,

Tobias.

Tobias Beer

unread,
Jan 24, 2017, 5:15:18 PM1/24/17
to TiddlyWiki
Hi Xavier,

Here's the whole roundtrip for you
to play with on http://tobibeer.github.io/tw5-plugins:

\define state() $:/state/selected/tags/$(tag)$

Select tags to constrain results...

<$set name="selected" filter="[prefix[$:/state/selected/tags/]has[text]removeprefix[$:/state/selected/tags/]]">
<$reveal type="match" default=<<selected>> text="">
<$list filter="[tag[Plugins]tags[]sort[title]]" variable="tag">
<$checkbox tiddler=<<state>> field="text" checked="true" unchecked="">
<$text text=<<tag>>/>
</$checkbox>
</$list>
</$reveal>
<$reveal type="nomatch" default=<<selected>> text="">
<$list filter="[contains:tags $all<selected>tags[]!title[Plugins]sort[title]]" variable="tag">
<$checkbox tiddler=<<state>> field="text" checked="true" unchecked="">
<$text text=<<tag>>/>
</$checkbox>
</$list>
</$reveal>

<dl>
<$list filter="[contains:tags $all<selected>sort[title]]">
<dt><$link><$view field="title"/></$link></dt>
<dd class="tb-links">''tags:'' {{{ [all[current]tags[]!title[Plugins]] }}}</dd>
</$list>
</dl>
</$set>

Best wishes,

Tobias.

Xavier Cazin

unread,
Jan 25, 2017, 4:36:14 AM1/25/17
to tiddl...@googlegroups.com
Hello Tobias,

Thank you so much for having put your time and insight on my problem. You even solved the configuration interface issue that I had left aside :-) Your code work beautifully and it just gives me the kick to move forward.

Thanks again.

-- Xavier Cazin

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
Reply all
Reply to author
Forward
0 new messages