Generating links depending on field value

48 views
Skip to first unread message

Darek Bobak

unread,
Sep 17, 2020, 9:28:00 AM9/17/20
to TiddlyWiki
I cannot get simple, as I suppose, result:

There is a field. Let's say, bibtex-doiuri.

If the field has any value, i'd like to get as an output:
[[DOI|content_of_the_field]]

If the field is empty, i'd like to get nothing. An empty string.
The result should appear within the $list widget (if it matters).

Darek.

Eric Shulman

unread,
Sep 17, 2020, 10:08:38 AM9/17/20
to TiddlyWiki
On Thursday, September 17, 2020 at 6:28:00 AM UTC-7, Darek Bobak wrote:
There is a field. Let's say, bibtex-doiuri.
If the field has any value, i'd like to get as an output:
[[DOI|content_of_the_field]]
If the field is empty, i'd like to get nothing. An empty string.
The result should appear within the $list widget (if it matters).

First, define a macro that assembles the desired output, like this:
\define MakeDOILink() [[DOI|$(uri)$]]

Next, define a macro that gets a field value and passes it to the MakeDOILink, like this:
\define DOILink() <$list filter="[<currentTiddler>get[bibtex-doiuri]]" variable="uri"><<MakeDOILink>></$list>
If the field "bibtex-doiuri" is empty (or doesn't exist) then the get[...] filter doesn't produce any result, and thus <<MakeDOILink>> is not invoked.

Then, to use it, just write:
<<DOILink>>

enjoy,
-e

Darek Bobak

unread,
Sep 17, 2020, 11:25:41 AM9/17/20
to TiddlyWiki
Great, thaks! I didn't come up with an idea to use the $list widget

best
Darek
Reply all
Reply to author
Forward
0 new messages