Create a link using a variable built from <$list>

I’m trying to put together a basic bibliography section to cite my sources but I’d like to be able to create a field for each source that links to a source wiki page. I would also like to name each field ‘source-1’, ‘source-2’, …, ‘source-n’, so I can keep them organized.

If there is a better way to do this, please let me know!

I’ve tried two different ways to do this while extracting the number (n) from ‘source-n’ but for each method, I get stuck.

Method 1:

<$list filter="[<currentTiddler>fields[]prefix[source-]split[source-]!is[blank]]" variable="num">
<$vars source="source-<<num>>">
<$vars s={{{ [<currentTiddler>get<source>] }}}>
  <span class="source">[<<num>>]: <$link to=<<s>> /></span><br />
</$vars>
</$vars>
</$list>

This fails as <<s>> doesn’t actually contain any data (even though <<source>> outputs “source-1”), however if I replace

<$vars source=“source-<<num>>”>

with

<$vars source=“source-1”>

I can get the appropriate link but only to the source entered into the field ‘source-1’ (as it’s hard-coded in).

So, my question here would be: how can I create the variable <<s>> dynamically from <<num>>?

Method 2 (basically the inverse of Method 1):

<$list filter="[<currentTiddler>fields[]prefix[source-]]" variable="source">
<$vars s={{{ [<currentTiddler>get<source>]}}}>
  <span class="source">[<<source>>]: <$link to=<<s>> /></span><br />
</$vars>
</$list>

This works great but how can I extract out the source number and place it into the <span> (currently the span shows [source-1]…, [source-2]… etc. and I want it to show [1], [2], etc.

Thank you for any help or if you know a much better way to build a bibliography.

Try

<$vars source={{{ [[source-]addsuffix<num>] > }}}

1 Like

I think the best way to manage references and automate it in tiddlywiki is from Mohammad’s refnote plugin – Refnotes 1.8.3 — references, citations, footnotes and abbreviations in Tiddlywiki

You also need bibtex importer plugin from TW official page.
It has detailed tutorials on bibtex as well.

There was a typo as the > was before the }}} instead of after in

<$vars source={{{ [[source-]addsuffix<num>] > }}}

Also, it is now best to use $let instead of $vars.

<$let source = {{{ [[source-]addsuffix<num>] }}}>

But why split the number from “source-” to attach them right again? I suggest the simpler code below.

<$list variable=source filter="[<currentTiddler>fields[]prefix[source-]split[source-]!match[source-]]">
  <$let num = {{{ [<source>removeprefix[source-] }}}
       src={{{ [<currentTiddler>get<source>!is[blank]else[No source provided error!]] }}}
   >
  <span class="source">[<<num>>]: <$link to=<<src>> /></span><br />
  </$let>
</$vars>
</$list>

I have introduced the !match[source-] to get exactly what you were testing for with !is[blank] in your code, although I doubt you would have a ‘source-’ name. Were you not rather looking for an empty list? This would not even be needed with <$list>.

Not also that I have make sure that src is not empty, that would be strange. Better spot the problem.