Hi everyone,
With Springer's help and and bit of googling around, I finally found a
(basic) working solution. Yay!
It is much simpler to use a ViewTemplate instead of a macro and it should
satisfy most of my needs.
Should it be useful to anybody, here is the code I used in the ViewTemplate
to replace the macro:
```
<$list
filter="[all[current]field:tiddler-type[exercice]field:displaysource[yes]]">
<$set name="fieldCount" filter="[all[current]fields[]prefix[ref_]count[]]">
<$text text={{{ [<fieldCount>match[0]then[Pas de ]else<fieldCount>] }}} />
<$text text={{{ [<fieldCount>!match[1]then[sources :]else[source :]] }}} />
</$set><ul>
<$list filter="[all[current]fields[]prefix[ref_]sort[title]]"
variable="fieldName">
@@color:grey;
<li>
<$transclude field=<<fieldName>>/>
</li>@@
</$list>
</ul>
</$list>
```
I can't believe how great and versatile TiddlyWiki is!!
Regards
Le mardi 20 juillet 2021 à 18:35:59 UTC+2, Misterel85 a écrit :
> Springer,
> Thanks a lot for taking the time to reply and for your help.
>
> You're exactly right: I'd like my macro to count (and then display one
> summary line for) each of the fields that start with ref_ in every tiddler
> in the story river.
>
> I have tried your solution to add `all[current]` in my macro but
> unfortunately it doesn't work.
> Actually because the macro is in its own tiddler, I think `all[current]`
> tries to find the ref_ fields in the macro's tiddler. But I may be wrong.
>
> Grok TiddlyWiki is a great tool to learn, but I haven't finished reading
> it, and it needs time to figure out all the intricacies of (TW) programming
> when your coding knowledge amounts to next to nothing.
>
> Regards
>
>
> Le mardi 20 juillet 2021 à 17:32:35 UTC+2, springer a écrit :
>
>> Misterel,
>>
>> I am *not* the expert; others could probably write the code you need in
>> 60 seconds. But since nobody else has answered, and understanding your task
>> and its problems demands some time and attention, I'll offer one nudge to
>> start...
>>
>> It seems you want your macro to count (and then display one summary line
>> for) each of the CURRENT tiddler's fields that start with ref_ -- Is that
>> correct?
>>
>> Instead, your macro is counting (and then displaying one summary line
>> for) every field in your whole wiki that begins with ref_
>>
>> Try pasting your code (with the variable filled in) and this alternate
>> code, into your Exercice1 tiddler. Your code yields 5, because the whole
>> project had five ref_ fields; but beginning your filter with
>> [all[current] gets you the number you want.
>>
>> First segment of your existing macro's code (specifying the prefix):
>> <$set name="fieldCount" filter="[fields[]prefix[ref_]count[]]">
>> <$text text={{{ [<fieldCount>match[0]then[Pas de ]else<fieldCount>] }}} />
>> <$text text={{{ [<fieldCount>!match[1]then[sources :]else[source :]] }}}
>> />
>> </$set>
>>
>> Better:
>> <$set name="fieldCount"
>> filter="[all[current]fields[]prefix[ref_]count[]]">
>> <$text text={{{ [<fieldCount>match[0]then[Pas de ]else<fieldCount>] }}} />
>> <$text text={{{ [<fieldCount>!match[1]then[sources :]else[source :]] }}}
>> />
>> </$set>
>>
>> All I'm doing here is the technique in https://groktiddlywiki.com/read/
>>
>> That is: breaking down a complex problem into smaller bits, and getting
>> your macro to count right *before* trying to set it up in the ViewTemplate
>> with an additional variable for the prefix and an additional condition for
>> displaysource[yes].
>>
>> Alas, I need to switch to other tasks, but I hope you're on the road to
>> getting the behavior you need.
>>
>> -Springer
>>
>> On Monday, July 19, 2021 at 11:08:53 AM UTC-4 Misterel85 wrote:
>>
>>> Hi,
>>> I'm back to work on a TiddlyWiki to manage my collection of drama
>>> exercises, but I came across 2 problems with displaying their sources and
>>> refreshing that display.
>>>
>>> Problem #1:
>>>
>>> My 'exercises' tiddlers all refer to a 'SourceDisplay' macro to show the
>>> sources.
>>> If I use a field to trigger the macro to show or hide the sources, they
>>> appear in 'Exercise1' tiddler, but not in 'Exercise2'. If I paste
>>> <<SourceDisplay prefix:"ref_">> in the text field of each of the
>>> Exercise tiddlers, it works fine.
>>> I suppose something like 'qualify' might solve the trick, but I don't
>>> know how to use it. Perhaps any of you has a better solution to suggest
>>> anyway, but I can make do with copying-pasting the macro call.
>>>
>>> Problem #2 (more serious to me):
>>> I changed the contents and title of tiddler "source1" to a more
>>> realistic name ('Dramaction' here) and contents and updated the the fields
>>> accordingly.
>>>
>>> I made 4 dummy source tiddlers. When I deleted the 'ref_source1' field
>>> in 'Exercise1' and replaced it with a 'ref_dramaction' field, I also
>>> noticed that there were now 4 sources in the list instead of 3. One line is
>>> blank, which I suppose is the ghost of 'source1', without any data, of
>>> course, since that content doesn't exist any more. It's as if old 'source1'
>>> data wasn't purged, or TW still expected that content to exist alongside
>>> the new 'dramaction' content. It also happens every time I delete one of
>>> those fields.
>>>
>>> Also, when I delete the 'ref_source1' field in 'Exercise2', the list of
>>> sources gets updated in 'Exercise1', but not in Exercise2, which showed the
>>> same problem as in the previous paragraph.
>>>
>>> Thanks in advance for your help.
>>>
>>>
>>> Here is the link to a MWE you can download, to see what I mean:
>>>
>>>
>>> https://u.pcloud.link/publink/show?code=XZmdnCXZmtUJk3s4tCfxvYwlXQmYnXrL8RJV
>>>
>>> And below is the macro I am talking about:
>>>
>>> ```
>>> \define SourceDisplay(prefix:"")
>>> <$set name="fieldCount" filter="[fields[]prefix[$prefix$]count[]]">
>>> <$text text={{{ [<fieldCount>match[0]then[Pas de ]else<fieldCount>] }}}
>>> />
>>> <$text text={{{ [<fieldCount>!match[1]then[sources :]else[source :]]
>>> }}} />
>>> </$set>
>>> <span class="source">
>>> <ul>
>>> <$list filter="[fields[]prefix[$prefix$]sort[title]]"
>>> variable="fieldName">
>>> <li>
>>> <$transclude field=<<fieldName>>/>
>>> </li>
>>> </$list>
>>> </ul>
>>> </span>
>>> \end
>>> ```
>>>
>>>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/97332068-5aec-43e0-8362-b274c6772862n%40googlegroups.com.