The filtered transclusion is a very useful feature of tiddlywiki, we are familiar with the triple curly braces {{{ filter }}} and commonly made into plain text with <$text text={{{ filter }}}/>, however as an attribute only the first value is given.
I was wondering “If there is a long form version of filtered transclusions?” and if not what would it take to make one available?
For example add a $filter parameter to the Modern $transclude widget.
We could use the long form and use other parameters like the $output parameter.
We could also “not limit”, the output to the first only.
One example <$transclude $filter=" filter " $output="text/plain"/> with no need to use the text widget.
We can add +limit[1]] or first[] to the filter if one value is needed, even last[] if relevant.
But also allow other transclude parameters to be used. In one example also using the $output parameter. However there may not be many relevant parameters.
In particular I was hoping for a long form in the transclude widget to use templates etc… But it seems there is no existing long form of filtered transclusions.
I may just build the features I want into a transcludable tiddler making use of they new features.
That’s a shorthand for a list-widget with a template parameter. You can see that in the Parse-Tree preview pane- There is no need to include code into the transclude widget, that is already part of the list-widget.
So it is fair to say that the long form of “filtered transclusions” is a list widget?
I will have to concider this again and see if there are gaps, even the methods I may use and the new transclusion, features to understand this, but thanks for the answer @pmario and the method you used.
The template parameter on the list widget is a form of transclusion, so a deeper look at the posibilities is warented.
Yes. That’s right. There have been some discussions at GitHub if that was the best decision to be made. Especially since the default template of the list-items are links and not plain text. But it was a convenient shortcut as it was invented.
That’s one reason, why the new \function definition exists.
Assigning a filtered transclusion to a variable technically is a bit hacky. But in the early days there has been no other way to resolve a filter and assign it to a variable.
Yes, I am experimenting with the list widget, and a template, or transclude widget to create the equivalent, in which I may be able to use some of the new form of transclued;
We could – But that would be a compatibility problem. Every bit of code, that assumes otherwise would need to be changed.
There is only 1 widget, that can deal with an “array” of elements as a filter output. That’s the list-widget.
So it does not really make sense to allow an assignment of “arrays” to other widgets. They cannot handle them directly as an array. If several HTML elements have to be created, there has to be a list-widget somewhere.
In the OP you wrote we could use the first[] operator like: <$text text={{{ [tag[HelloThere]first[]] }}}/> if we would want to limit a list to 1 element as an output. – That’s right.
The same is true If I say:
We can use <$text text=`${ [tag[HelloThere]format:titlelist[]join[ ]] }$`/> to show the whole list. It’s absolutely the same argument. – Just the other way around.
We could argument that the later construction is more complex.
I’d say: Not if we use <$set name=myList filter="[tag[HelloThere]]">, which is the generic way to assign “arrays” to a variable.
So using the set-widget with a filter, we can do both:
Define a myList variable
<$set name=myList filter="[tag[HelloThere]]">
and oneTitle
<$set name=oneTitle filter="[tag[HelloThere]first[]]">
If you have a closer look at the screenshots, you’ll also see, that the \function pragma internally is translated to a set-widget with a isFunctionDefinition: true in the parse-tree.
That’s also true for \define and \procedure. Internally they are variables with a isX marker
Thanks @pmario that restates things nicely. If a widget does not know how to handle a list I am fine with that, but what If I wanted to pass a list to a custom widget or html designed to handle a list;
<$mywidget list=`$( [tag[HelloThere]] )$`/>
I cant because only the fist item will be given
Now imagin I was granted another form say ($ filter $) that did not do this, but set the attribute to the whole list
<$mywidget list=`($ [tag[HelloThere]] $)`/>
Then without any fuss I could set an attribute to a list of values, whenever I wanted without any of these confusing work arounds.
It breaks no rules, at worst it allows you to give lists to parameters that dont handle it as a list, just as a string. I would no longer beforced to accept first only on attribute values.
What if my list was a valid multivalue string list float: right; width:50% generated by a filter ?
Similarly I have to use the <$text text="code"/> quite a lot so it would be nice if we had a shorthand, perhaps wikitext, for this too. Which is why I was asking in the OT for the long form of the transclude, to see if I could just make the output plain text.
I suspect slot/fill may provide one method with transclusions, but again its much more long winded that having a mechanisium that does not force the “first only”.
The enlist and enlist-input operators can split them into arrays again, that can be used by the list-widget, which can be part of your own widget if you need it that way.
If you need to deal with parameter names and parameter values that you do not know upfront, you’ll need to deal with the $names and $values parameters from the genesis-widget … They also need title-list like values