Using variables in nested lists

200 views
Skip to first unread message

Diego Mesa

unread,
Dec 1, 2017, 3:04:41 PM12/1/17
to TiddlyWiki
Hey all,

I am trying to display a header for all posts tagged PoI that does, among other things, display any urls I've placed in its fields. For example, If I have a tiddler with the following fields:

paper-url: test1.com
hn-url: test2.com
blog-url: test3.com

I would like to have displayed

Paper: test1.com
Blog: test3.com

as the header. This is what I have so far:

<$list filter="[is[current]fields[]regexp[-url]]" variable="fieldname">
<$list filter="[[<<fieldname>>]split:before[-]]" variable="fieldprint">
<$text text=<<fieldprint>>/> : <$view  field=<<fieldname>>/> <br>
</$list>
</$list>

But this does not work. Without the split-before it renders as:

<<fieldname>> : test1.com 
<<fieldname>> : test2.com
<<fieldname>> : test3.com

which signifies that the <<fieldname>> isn't getting substituted correctly in the inner list. I tried adding a <$set> between the nesting, but that didn't work either. 

Any specific (and general!) help would be greatly appreciated!
Diego


Diego Mesa

unread,
Dec 1, 2017, 3:29:02 PM12/1/17
to TiddlyWiki
After reading/searching/experimenting I got:

<$list filter="[is[current]fields[]regexp[-url]]" variable="fieldname">
<$list filter="[
<fieldname>split:before[-]]" variable="fieldprint">
<$text text=<
<fieldprint>>/>: <$view  field=<<fieldname>> /> <br/>

</$list>
</$list>

There is still some confusion about the use of << vs < when referencing variables, and why I don't have to wrap <fieldname> with [<fieldname>] before giving it to split. 

Remaining issues:
  • actually making those render as URLs
  • If I replace the <br/> with a comma to get them all on one line, I'm left with a trailing comma
  • If I instead try to generate external links as:  [[<$text text=<<fieldprint>>/>|<$view field=<<fieldname>> />]]   it doesn't work. 
There is still some residual confusion about using nested lists as nested for loop analogs, and how to actually use the variables in the "loops".

Xavier Cazin

unread,
Dec 1, 2017, 3:29:30 PM12/1/17
to tiddl...@googlegroups.com
Hi Diego,

I think your second line should read:

<$list filter="[<fieldname>splitbefore[-]removesuffix[-]]" variable="fieldprint">

Best,
Xavier.

-- Xavier Cazin

--
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 tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/db3685f8-d0b7-49c5-9c87-153e82c2ae3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Xavier Cazin

unread,
Dec 1, 2017, 3:49:10 PM12/1/17
to tiddl...@googlegroups.com
Hi Diego,

I think the following butlast/last trick was given by Jed Carty a few hours ago. It looks quite verbose because the outer list is essentially duplicated, but I think it handles your three issues.

<$list filter="[is[current]fields[]regexp[-url]butlast[]]" variable="fieldname">
<$list filter="[<fieldname>splitbefore[-]removesuffix[-]]" variable="fieldprint">
<$text text=<<fieldprint>>/> : <$link to=<<fieldprint>>><$view  field=<<fieldname>>/></$link>,
</$list>
</$list>
<$list filter="[is[current]fields[]regexp[-url]last[]]" variable="fieldname">
<$list filter="[<fieldname>splitbefore[-]removesuffix[-]]" variable="fieldprint">
<$text text=<<fieldprint>>/> : <$link to=<<fieldprint>>><$view  field=<<fieldname>>/></$link>.
</$list>
</$list>

Best,
X.


-- Xavier Cazin

--
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 tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Diego Mesa

unread,
Dec 1, 2017, 3:51:20 PM12/1/17
to TiddlyWiki
Thanks Xavier! I was using tobias split:before, but I think that will also work.

Another update! I am almost there with:

<$list filter="[is[current]fields[]regexp[-url]]" variable="fieldname">
<$list filter="[
<fieldname>
split:before[-]]" variable="fieldprint">
''<$text text=<
<fieldprint>>/>'': <$transclude field=<<fieldname>> mode="inline"/>,
</$list>
</$list>

I still can't figure out how to not show the last comma. 

P.S. Sorry to keep spamming this with updates. You could see this as I prematurely posted and should have waited till I did more figure out, but: 1. The act of asking clarifies for me 2. Posting this thought process/evolution might be useful to others in the future! 

-- Xavier Cazin

To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

Diego Mesa

unread,
Dec 1, 2017, 3:53:20 PM12/1/17
to TiddlyWiki
Thanks Xavier! I think that butlast and last will work! 

-- Xavier Cazin

To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Jed Carty

unread,
Dec 1, 2017, 4:05:24 PM12/1/17
to TiddlyWiki
For getting rid of the last comma, the same method I demonstrated here should work: https://groups.google.com/d/msg/tiddlywiki/D5CQvz_CpYw/0J0phbL4AwAJ

Jed Carty

unread,
Dec 1, 2017, 4:07:43 PM12/1/17
to TiddlyWiki
Sorry, looking at that now it isn't obvious what I am talking about but it looks like you already have the same idea anyway using last and butlast.

Diego Mesa

unread,
Dec 2, 2017, 10:29:05 PM12/2/17
to TiddlyWiki
Can some one clarify on the use of << vs < when referencing variables, and why I don't have to wrap <fieldname> with [<fieldname>] before giving it to split. 

Thanks!

Eric Shulman

unread,
Dec 3, 2017, 12:24:52 AM12/3/17
to TiddlyWiki
On Saturday, December 2, 2017 at 7:29:05 PM UTC-8, Diego Mesa wrote:
Can some one clarify on the use of << vs < when referencing variables...

In TiddlyWiki *content*, variables are referenced using <<variableName>>.  The double-bracket syntax is used to avoid conflicts with standard HTML syntax (i.e., <b> starts normal HTML bold formatting, while <<b>> embeds the value of a TiddlyWiki variable named "b")

However, within TiddlyWiki *filters*, there is no need doubling the brackets, as HTML is not allowed *within* the filter, so only single <variableName> is used.

...and why I don't have to wrap <fieldname> with [<fieldname>] before giving it to split. 

Think of the brackets in filters as part of the operand itself rather than a "container" for the operand.  The type of bracket indicates the type of operand being used:
   use [...] for literal values, e.g., [texthere] 
   use {...} for field references, e.g., {!!fieldname}
   use <...> for variables e.g. <currentTiddler>

Thus, to split the literal text, "sometext", you could write:
   [title[sometext]splitbefore[t]removesuffix[t]]
you would get "some" as a result.

If the value "sometext" is stored in a field named "somefield" in the current tiddler, you could write:
  [{!!somefield}splitbefore[t]removesuffix[t]]

and, if the value "sometext" is stored in a variable named "somevariable", you could write:
  [<somevariable>splitbefore[t]removesuffix[t]]

As a slightly more complex example, suppose the value to split on was also stored in a variable.  Then you could write:
  [<somevariable>splitbefore<othervariable>removesuffix<othervariable>]

hope this helps,

enjoy,
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas!" (tm)
InsideTiddlyWiki: The Missing Manuals

Diego Mesa

unread,
Dec 3, 2017, 7:28:57 PM12/3/17
to TiddlyWiki
Thanks for this explanation Eric! I've made a note in my wiki! 
Reply all
Reply to author
Forward
0 new messages