[TW5] Concatenated Widget Parameters

852 views
Skip to first unread message

Tobias Beer

unread,
Nov 18, 2014, 2:32:02 PM11/18/14
to tiddl...@googlegroups.com
Is there any way on how to achieve something like this...

<$link to="$:/language/Docs/Fields/{{!!title}}">{{!!title}}</$link>

?

Best wishes, Tobias.

Stephan Hradek

unread,
Nov 18, 2014, 4:10:06 PM11/18/14
to tiddl...@googlegroups.com
\define languageDocsFields() $:/language/Docs/Fields/$(currentTiddler)$

<$link to=<<languageDocsFields>>><$view field="title"/></$link>

Tobias Beer

unread,
Nov 18, 2014, 4:14:06 PM11/18/14
to tiddl...@googlegroups.com
Hi Stephan,

Thanks, I was hoping I could avoid using an extra macro just to concatenate the two.
 
\define languageDocsFields() $:/language/Docs/Fields/$(currentTiddler)$
 
I guess it's going to be a generic concat macro instead.

Best wishes, Tobias.

Stephan Hradek

unread,
Nov 18, 2014, 4:17:59 PM11/18/14
to tiddl...@googlegroups.com
Remember that there seems to be a problem with unnamed parameters and the $macrocall widget. As far as I know, it's not possible to use it without specifying parameter names.

But if the macro should be generic, I think you should go for a javascript macro with unlimited parameters.


Tobias Beer

unread,
Nov 18, 2014, 4:24:40 PM11/18/14
to tiddl...@googlegroups.com
Hi Stephan,

The usecase wasn't actually that generic, after all. ;-)


See tab "standard".

Best wishes, Tobias.

Stephan Hradek

unread,
Nov 18, 2014, 4:33:47 PM11/18/14
to tiddl...@googlegroups.com
Here is a generic "join" filter:

/*\
title: $:/core/modules/filters/join.js
type: application/javascript
module-type: filteroperator

Filter operator that concatenates all tiddlers from the current list, using the operator as the seperator

\*/

(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Export our filter function
*/

exports
.join = function(source,operator,options) {
       
var result = '';
        source
(function(tiddler,title) {
                result
+=operator.operand + title;
       
});
       
return [ result.substr(operator.operand.length) ];
};

})();


Example for usage:

<$list filter="[[$:]] [[language]] [[Docs]] [[Fields]] [all[current]] +[join[/]]">
<$view field="title"/>
</$list>

Or shorter:

<$list filter="[[$:/language/Docs/Fields]] [all[current]] +[join[/]]">
<$view field="title"/>
</$list>




Tobias Beer

unread,
Nov 18, 2014, 4:54:39 PM11/18/14
to tiddl...@googlegroups.com
Here is a generic "join" filter:

Did you just write that or did it come from an already brighter place? ^_^

Would it be sufficient to give the above code tiddler a type of application/javascript so as to have it run after restart?

Best wishes, Tobias.

Stephan Hradek

unread,
Nov 18, 2014, 4:56:21 PM11/18/14
to tiddl...@googlegroups.com


Am Dienstag, 18. November 2014 22:54:39 UTC+1 schrieb Tobias Beer:
Here is a generic "join" filter:

Did you just write that or did it come from an already brighter place? ^_^
 
Just wrote it. 5minutes including testing.
 
Would it be sufficient to give the above code tiddler a type of application/javascript so as to have it run after restart?

Type and field are listed in the tiddler. After setting those and restarting you're ready to go.

Tobias Beer

unread,
Nov 18, 2014, 4:59:47 PM11/18/14
to tiddl...@googlegroups.com
Hi Stephan,
 
Just wrote it. 5minutes including testing.

Kudos! Any chance you'd up this and alike codebits to a GitHub repo of yours? Where?

Best wishes, Tobias.

Stephan Hradek

unread,
Nov 18, 2014, 5:04:17 PM11/18/14
to tiddl...@googlegroups.com


Am Dienstag, 18. November 2014 22:59:47 UTC+1 schrieb Tobias Beer:
Any chance you'd up this and alike codebits to a GitHub repo of yours? Where?

Not at the moment. I simply don't feel like it.

Tobias Beer

unread,
Nov 18, 2014, 5:47:59 PM11/18/14
to tiddl...@googlegroups.com
Hi Stephan,
 
 Not at the moment. I simply don't feel like it.

Sure thing, was just curious if that existed.

Any idea why using the variable as declared in the set widget won't work with the list widget?

<$set name="field" value="title">
<$list filter="[[$:/language/Docs/Fields]] [[$field$]] +[join[/]]">
$field$: <$view field="title"/>
</$list>
</$set>

The timelinemacro seems to use variables in its filter just fine...

Best wishes, Tobias.

Stephan Hradek

unread,
Nov 19, 2014, 12:28:18 AM11/19/14
to tiddl...@googlegroups.com
Am Dienstag, 18. November 2014 23:47:59 UTC+1 schrieb Tobias Beer:

Any idea why using the variable as declared in the set widget won't work with the list widget?

Yes. Variables don't work there. You need an additional macrocall. Additionally you forgot the brackets arounf the variablename: $(field)$

Tobias Beer

unread,
Nov 19, 2014, 4:18:51 AM11/19/14
to tiddl...@googlegroups.com
Hi Stephan,
 
Any idea why using the variable as declared in the set widget won't work with the list widget?

Yes. Variables don't work there. You need an additional macrocall. Additionally you forgot the brackets arounf the variablename: $(field)$

That's also one thing I find quite confusing, at what point can I use $field$ and at what point do I have to $(field)$?
The documentation on variables only mentions the latter, although I've found the former to be quite ubiquitously used.
Also, are there limitations to using either $variable$, $(variable)$ or <<variablename>>? If yes: documentation.

Best wishes, Tobias.

Stephan Hradek

unread,
Nov 19, 2014, 5:36:40 AM11/19/14
to tiddl...@googlegroups.com
This is my understanding:

$i_am_a_macro_parameter$ - replaced upon macro execution

$(i_am_a_variable)$ - replaced upon macro execution

<<i_am_a_variable_or_macro>> - executed... I don't exactly know when

Stephan Hradek

unread,
Nov 19, 2014, 1:15:33 PM11/19/14
to tiddl...@googlegroups.com


Am Mittwoch, 19. November 2014 18:39:47 UTC+1 schrieb Danielo Rodríguez:
It's pretty easy :
$(var)$ for variable substitution inside macro
$var$ for macro parameter
<<var>> for transclude the variable value within normal wikitext or as parameter of widget calls.

Does that make sense for you? It took a while to me to sort this in my mind.

And we both forgot <var> for usage in filters.
Message has been deleted

Jed Carty

unread,
Nov 20, 2014, 6:56:41 PM11/20/14
to tiddl...@googlegroups.com
I put in a pull request to update the variables in wikitext tiddler that adds examples of when $(name)$ <<name>> and <name> are used.

From what I understand you use $(var)$ when you set a variable outside of a macro and then use that variable in the macro and <<var>> is for setting a variable and using it outside a macro. In both of these cases adding quotes returns the variable value surrounded by quotes. so

<$set name='var' value='someValue'>
<<var>> "<<var>>"
</$set>

gives: someValue "someValue". <<var>> acts the same inside a macro as outside, and if the value is set as a filter it can be used as a filter.

<var> in wikitext it parsed as an html tag from what I can tell, so it breaks things and doesn't display as anything. Adding quotes ("<var>") is the same as putting quotes around any tag where it displays quotes.

Variable names called by $var$ and "$var$" are just strings so they are displayed like any other string without any substitution, inside or outside a macro.

In [[<var>]], <var> is treated as a string, so that would create a link to a tiddler with the title <var>

The times when <var> DOES work is in a situation like this:

<$set name='var' value='someTag'>
<$list filter='[tag<var>]'/>
</$set>

which lists tiddlers tagged with someTag. This should work inside or outside a macro. Using '[tag[$(var)$]]' as a filter anywhere gives the tiddlers that are tagged with $(var)$ without any substitution.

As for parameters passed to a macro the only options you have that are not treated as strings (so no substitution, and [[<param>]] links to the tiddler with title <param>) are $param$ and "$param$" in both cases the input is substituted for $param$ without any weirdness.
So

\define macroThing(param)
[[$param$]]
\end

<<macroThing HelloThere>>

displays a link to the tiddler HelloThere.

I think that a significant amount of weirdness comes in when you have things like this:
<$set name='someVar' value={{!!title}}>

Where "<<someVar>>" gives "HelloThere" if you are in the HelloThere tiddler, but calling a macro with <<macroName "<<someVar>>">> gets parsed as calling macroName with the input "<<someVar treated as a string. This is why you use $(someVar)$ inside the macro to reference the variable.
Passing something like {{!!title}} as the input to a macro can be strange because in that case it isn't evaluated, it is straight text substitution.

So this code:

\define someMacro(input)
<$list filter='[tag[$input$]]'/>
\end

<<someMacro {{!!title}}>>

returns a list of tiddlers tagged {{!!title}} with no substitution, but if you use this

\define someMacro()
<$list filter='[tag[$(input)$]]'/>
\end

<$set name='input' value={{!!title}}>
<<someMacro>>
</$set>

 you get a list of all tiddlers tagged with the current tiddler.

I am not sure if any of that made sense, but I am pretty sure it is all correct.

Tobias Beer

unread,
Nov 21, 2014, 4:49:05 AM11/21/14
to tiddl...@googlegroups.com
Thanks a lot Jed,

I turned your excellent overview into an example wiki...


...also referenced here:


Best wishes, Tobias.

Jeremy Ruston

unread,
Nov 22, 2014, 12:21:14 PM11/22/14
to TiddlyWiki
Hi Tobias

> Any chance you could fill this table with numbers according to spec (=implementation)?

I find the table a bit confusing. The underlying situation is much simpler:

* Textual substitution for $parameters$ and $(variables)$ only takes place within macro bodies
* Transcluding a variable with <<variable>> is a basic wikitext construct that can also be used for widget/html element attributes
* Transcluding a tiddler text reference with {{title}} is a basic wikitext construct that can also be used for widget/html element attributes
* Filters use [<variable>] for a variable transclusion, and [{title}] for a tiddler transclusion

I turned your excellent overview into an example wiki...

You've been very productive recently! I'd like to link to your new TW5 stuff, what's the best base URL to use?

Best wishes

Jeremy.
 

--
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+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Tobias Beer

unread,
Nov 22, 2014, 1:36:32 PM11/22/14
to tiddl...@googlegroups.com, jeremy...@gmail.com
Hi Jeremy,
 
I find the table a bit confusing. The underlying situation is much simpler:

* Textual substitution for $parameters$ and $(variables)$ only takes place within macro bodies
* Transcluding a variable with <<variable>> is a basic wikitext construct that can also be used for widget/html element attributes
* Transcluding a tiddler text reference with {{title}} is a basic wikitext construct that can also be used for widget/html element attributes
* Filters use [<variable>] for a variable transclusion, and [{title}] for a tiddler transclusion

Thanks for the consolidated list! I will use it to try fill the above table with the expectated behavior and do some testing in...


Not sure where to place such a consolidated aggregation in tiddlywiki.com. Imho, it would be good if it were not just scattered all about different module documentations.

I did some updating and consolidation at the page below. Please, be so kind to take a quick look, and let me know if anything's off...


I turned your excellent overview into an example wiki...

You've been very productive recently! I'd like to link to your new TW5 stuff, what's the best base URL to use?

Yes, trying to catch up and using tb5 as a central hub for gathering tw5 know-how...


That's the place for me until that perhaps more distant moment where I might be doing some more segmented node.js-serving. Although I am doing that already, I might eventually split up contents into dedicated TiddlySpots to keep the load a bit at bay in tb5.

Best wishes, Tobias.

Jeremy Ruston

unread,
Nov 23, 2014, 8:30:34 AM11/23/14
to Tobias Beer, TiddlyWiki
Hi Tobias

>I did some updating and consolidation at the page below. Please, be so kind to take a quick look, and let me know if anything's off...


Note that "$macroParameter$" and [[$macroParameter$]] are both really a combination of two bits of syntax: double square brackets and double quotes to quote a tiddler title that might contain spaces, and the $dollar$ notation for substituting a macro parameter.

You've listed {{transclusion}} under "within macros" which might be misleading: there's no special handling for {{transclusion}} processing within macros; the transclusion is just part of the output of the macro and gets wikified at that point.

Similarly, listing <$widget param="$macroParameter$"/> as a way to pass widget parameters; it's again a compound syntax, whereas the other examples in that section are basic variants of the attribute syntax.

You are analysing all the combinations of two layers of syntax where I think it might be easier to understand if you instead focused on understanding the way that those two layers work and interact.

The two layers are ordinary wikitext processing and the special processing that occurs when macros are expanded. All of the complexity in your examples arises from macro-related syntax interacting with wikitext processing.

If we teach people that <$widget param="$macroParameter$"/> is an out-of-the-box syntax then they risk missing that they can do things like <$widget param="mytiddlertitleprefix-$macroParameter$"/>. The key is to gain an understanding of the two layers involved.

Best wishes

Jeremy.




 

Tobias Beer

unread,
Nov 23, 2014, 9:40:59 AM11/23/14
to tiddl...@googlegroups.com, beert...@gmail.com, jeremy...@gmail.com
 Hi Jeremy,

Thanks for taking the time to review, very helpful.
 
Note that "$macroParameter$" and [[$macroParameter$]] are both really a combination of two bits of syntax: double square brackets and double quotes to quote a tiddler title that might contain spaces, and the $dollar$ notation for substituting a macro parameter.

Yes, that is indeed obvious. My intention was to provide a quick visual that that's indeed the case to provoke an "sure thing" effect.
 
You've listed {{transclusion}} under "within macros" which might be misleading: there's no special handling for {{transclusion}} processing within macros; the transclusion is just part of the output of the macro and gets wikified at that point.

Yes, thank you. I have moved it to the "general wikitext" section and mentioned that it, of course, applies to a macro body just the same.

Similarly, listing <$widget param="$macroParameter$"/> as a way to pass widget parameters; it's again a compound syntax, whereas the other examples in that section are basic variants of the attribute syntax.

Good to know and be reminded that it's not just about widgets, but any html element attribute. I have renamed that section accordingly
 
If we teach people that <$widget param="$macroParameter$"/> is an out-of-the-box syntax then they risk missing that they can do things like <$widget param="mytiddlertitleprefix-$macroParameter$"/>. The key is to gain an understanding of the two layers involved.

Yes, so that is actually an very good example which I have now added, although surely important to know that the same does not work for macro parameters.

I have restructured the whole thing now and put it here for reference...

general wiki text, including macros
» <<variable>>
» {{transclusion}}
» <variable>"<variable>"[[<variable>]]
general html element attributes, including widgets, e.g. $macrocall
» <$widget attribute=<<variable>>/>
» <$widget attribute=<<callMacroToComputeValue>>/>
» <$widget attribute={{transclusion}}/>
» <$widget attribute="prefix-<<variable>>"/>
» <$widget attribute=[[prefix-<<variable>>]]/>
» <$widget attribute="prefix-{{transclusion}}"/>
within macro body
» $macroParameter$"$macroParameter$"[[$macroParameter$]]
» $(variable)$ (references a variable from the context of the calling macro)
» <$widget attribute="prefix-$macroParameter$"/>
» <$widget attribute=$macroParameter$/> (unsafe when having spaces)
» $variable$"$variable$"[[$variable$]]
macro parameter
» <<macro param="$macroParameter$">> (only inside macro)
» <<macro <<variable>> >>
» <<macro "<<variable>>" >>
» <<macro param:<<variable>> >>
» <<macro {{transclusion}}>>
» <<macro param:{{transclusion}}>>
in filters
» [$macroParameter$] (only filters within macros)
» [tag<variable>] (no inner square brackets!)
» [tag{transclusion}] (only single curly brackets!)
» [tag[$(variable)$]]
» [tag[$(variable)$]]

Best wishes, Tobias.

Danielo Rodríguez

unread,
Nov 19, 2014, 12:39:47 PM11/19/14
to tiddl...@googlegroups.com

Tobias Beer

unread,
Nov 19, 2014, 7:12:05 PM11/19/14
to tiddl...@googlegroups.com
@Jeremy,

Ok, here's a matrix of possible things people might try out, including me.

Any chance you could fill this table with numbers according to spec (=implementation)?
  • 1 means => designed / expected to work
  • 2 means => designed to work but known bug
  • 3 + means => not supported, each number preferably specifying the reason why
...the above of course with the expectation that a substitution will take place.
 
What's
allowed?
in
wiki
text
filter in
widget
call
param in
widget
call
widget
body
macro
call
macro
body
filter in
macro call in
macro body
param in
macro call in
macro body
filter in
widget call in
macro body
param in
widget call in
macro body
$param$
"$param$"
<<param>>
"<<param>>"
<param>
[[<param>]]
$var$
"$var$"
$(var)$
"$(var)$"
<<var>>
"<<var>>"
<var>
[[<var>]]

Whomever else wishes to make a guess, feel free. Will be interesting to compare results. ^_^
 
If provided, I will test all of the above in a meaningfully designed test wiki.

One more thing, when I read about Variables in WikiText[operator<variable-operand>], what exactly are the requirements for <variable-operand>?

Best wishes, Tobias.
Reply all
Reply to author
Forward
0 new messages