How to reference a field in another tiddler

Hello all

This is a follow-up to this discussion How to calculate the number of days between the dates in two fields

In my TW i have adapted the code from the example in https://tiddlywiki.com/#DateFormat copied below, as suggested by @TW_Tones

However, the various fields, eg modified and created are in another tiddler, determined by using

<$select field="select" >

in the current tiddler.

I simply cannot work out the syntax in the following code

<$let
	timestamp-modified={{{ [{!!modified}format:date[TIMESTAMP]] }}}
	timestamp-created={{{ [{!!created}format:date[TIMESTAMP]] }}}
	difference-days={{{ [<timestamp-modified>subtract<timestamp-created>divide[86400000]floor[]] }}}>
</$let>

to reference the fields in the tiddler determined by

<$select field="select" >

I thought it might be

timestamp-modified={{{ [{{select!!modified}}format:date[TIMESTAMP]] }}}

But that does not work!

Help would be greatly appreciated. Many thanks.

I think you are making two or more mistakes here, at once so it will not help you as much if I try and fix your code.

To get created and modified dates from a different tiddler you need to name that tiddler.

{{tiddlername!!fieldname}}

This is the transclude short cut if you are happy to hard code the title and fieldname.

  • In a filter you would use [{tiddlername!!fieldname}]

But we can also write this in a filter [[tiddlername]get[fieldname]] which has the advantage we can instead use variables such as [<target-tiddlername>get<target-fieldname>] or from local fieldnames [{!!target-tiddlername}get{!!target-fieldname}]

See how you go and feel free to ask follow-up questions.

Eg;

[{!!select}get[modified]format:date[TIMESTAMP]]

Many thanks @TW_Tones for your assistance.

With your help I have managed to produce the following:

<$let
	timestamp-date2={{{ [{!!select}get[date]format:date[TIMESTAMP]] }}}
	timestamp-date1={{{ [{!!select}get[start-date]format:date[TIMESTAMP]] }}}
	difference-days={{{ [<timestamp-date2>subtract<timestamp-date1>divide[86400000]round[]add[1]] }}}>


<$button>
<$action-setfield $tiddler={{!!select}} day-no=<<difference-days>> />
Update Elapsed Days
</$button>

</$let>

I use Tiddlywiki as a journal to record road trips in my campervan and to produce a static html blog for family and friends. I have a tiddler set up to allow me to edit the fields in the daily tiddlers. Using $select i can choose which tiddler to edit and the code above allows me to calculate and save the no of days I have been on the trip in each daily tiddler.

I have learnt a huge amount about Tiddlywiki through this exercise and from your help and that of many others on this forum.

Thank you all for your time.

Rob

1 Like