Field manipulation, lookup's lists and maths

On my tiddler I have a field where the field name is of the format another.tiddler.name (the field value is present but not relevant for this question). I am able to list these in the right format with use of a macro, so I am able to link to Another Tiddler Name with a macro like this;

@@text-transform: capitalize;<$text text={{{ [[$text$]search-replace:gi[.],[ ]] }}} />@@

and a list filter like this;

<$list filter="[all[current]fields[]sort[title]] -text -created -modified -tags -title -tmap.id" variable=“listItem”>
<$transclude tiddler="<$macrocall $name=“replaceFullStopAndCapitalize” text=<>/>" field=“cost”/>
</$list>

The problem I have is that its rendering as actual text rather than as the value, so instead of showing fieldValue it shows

<$transclude tiddler=“Another Tiddler Name” field=“cost”/>

The second problem, and while it would be nice, I can probably live without a solution to it, is that the field cost is a NUMBER and I would like to sum the numbers up and then output the sum. if I can only output the number I can make do but the sum would be really useful.

My current WIP is here Galactic Heroes — A Starwars Ruleset and I am using the plugin $:/plugins/ebalster/formula for the math’s

It would be easier just to have your macro generate the link right away. Or, if you also want a non-link version of the macro, keep it the way it is, and add another macro:

\define replaceFullStopAndCapitalizeLink(text)
{{{ [[$text$]search-replace:gi[.],[ ]titlecase[]] }}}
\end

Thanks, that’s useful and will save me some faff elsewhere but what I need is the value of the cost field on that other tiddler…

For getting a sum, you’ll need the :reduce operator.

I’m not confident with it yet, but I’m learning. You’ll want something like this:

<$text text={{{ <$list filter="[all[current]fields[]] -title -text -tags -created -modified :map[search-replace:gi[.],[ ]titlecase[]get[cost]] :reduce[add<accumulator>]"/>}}} />

(Tested, but you’ll need to tweak according to your needs.)

How it works: The string below takes your existing filter results (the list of custom fields), and turns EACH field.name into its cleaned-up (Field Name As) version…

:map[search-replace:gi[.],[ ]titlecase[]]

… then we “uncap” the final bracket of that expression to do more with this existing list of titles (note the expression below starts one “bracket-worth” deep):

get[cost]] :reduce[add<accumulator>]

So we’re going from the title list to the contents of the respective cost fields. Then tallying them all up with the “reduce” filter-run prefix and accumulator…

:slight_smile:

1 Like

The thing is: You don’t want to try to get one macro to “piggyback” on the calculated result of another.

Once you get the hang of filter expressions, you can often use them to get what you need more directly.

Cheers!

that looks so tantalizingly close/good but I get a value of 0 ;(

Do you have an example wiki to show? It’s working for me. I can post it shortly…

There is a link in my original post. Galactic Heroes — A Starwars Ruleset

Check it out here: permalink to “quick demo” tiddlers at tiddlyhost

;( why does it work there and not here!

Ah! you have older version
:map filter operator was introduced in TiddlyWiki v5.2.0

1 Like

ok, that’s a problem I can work around… Upgrade time!

Thankyou!