On Wednesday, January 6, 2016 at 11:31:51 AM UTC-8, Abraham Neben wrote:
>
> I want to loop over all task types (I have tiddler's called "home", and 
> "work", each tagged as "tasktype"), and for each one, list the names of all 
> tiddlers of that type also tagged as "task". 
>

You could use nested lists, like this:
<$list filter="[!has[draft.of]tag[tasktype]]" variable="tasktype"> 
   <$list filter="[!has[draft.of]tag[task]!tag[done]tag<tasktype>
sort[created]]">
      <$checkbox tag="done"> <$link to={{!!title}}><$view 
field="title"/></$link></$checkbox>
   </$list>
</$list>

* the outer <$list> loops over all tasktypes (i.e., "home", "work" etc.) 
and sets the variable, "tasktype"
* the inner <$list> loops over all tasks that are not done that are also 
tagged with the current task tasktype.

Note the angle brackets in the "tag<tasktype>" syntax is what allows you to 
use a variable value -- rather than the usual literal text -- as the 
operand of the tag[] filter. Also, using a named variable in the <$list>, 
instead of the default "currentTiddler", makes the overall meaning of the 
filter easier to understand.

One more "code style" tip that I sometimes use in my own projects: instead 
of putting filters and $list contents "inline", it can help to separate the 
parts into named macros, and then use those macros in the $list widgets. 
 This approach can make it much easier to understand the code, since it 
isolates some of the complex syntax and gives them symbolic names that help 
to emphasize their purpose.  For example, the previous code could be 
written this way:

\define types() [!has[draft.of]tag[tasktype]]
\define tasks() [!has[draft.of]tag[task]!tag[done]tag<tasktype>sort[created
]]
\define link()  <$link to={{!!title}}><$view field="title"/></$link>
\define check() <$checkbox tag="done"> <<link>></$checkbox>

<$list filter=<<types>> variable="tasktype"> 
   <$list filter=<<tasks>>>
      <<check>>
   </$list>
</$list>

While this coding style is not as compact, it is much more readable, as 
well as making it easier to do things like change the filter definitions or 
the output format. For example, you could add a "priority" field to your 
task tiddlers, and then then simply change this one line:
\define tasks() [!has[draft.of]tag[task]!tag[done]tag<tasktype>sort[priority
]]
without having to find the right place buried "inline" in the nested $list 
syntax.

enjoy,
-e

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/38f15639-3bb9-4114-98f0-c6c6f4174659%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to