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/fb3d9584-3602-42c8-ab3b-2da919ff4371n%40googlegroups.com.

Reply via email to