Variables within list get-stream-nodes filter [Solved]

Feel that surely this topic has been covered, but I have not found exactly what I’m looking for

I am trying to retrieve the titles and text of all the nodes in a stream-list. In the following example, I am using a simplified version:

<$set name="parentTitle" value="999">
<<parentTitle>>


<$list filter="[[<parentTitle>]get-stream-nodes[]]">
  <div>
    |  
    {{!!title}}  
    |  
    {{!!text}}  
  </div>
</$list>

If I can understand how to properly pass this variable into the list filter, I should be able to solve the larger problem I’m having.

Try this:

<$set name="parentTitle" value="999" select="0">
<<parentTitle>>


<$list filter="[<parentTitle>get-stream-nodes[]]">
  <div>
    |  
    {{!!title}}  
    |  
    {{!!text}}  
  </div>
</$list>

Edit: refer to this for syntax guidance for filter parameters: https://tiddlywiki.com/#Filter%20Parameter

That works!

Why did it work? lol. I will go over the filter parameters again, I don’t recall seeing anything about ‘select’

Not strictly necessary in this particular example but generally good practice when using the $set widget, see the section on Filtered Item Variable Assignment Single Element at https://tiddlywiki.com/#SetWidget:~:text=Filtered%20Item%20Variable%20Assignment%20Single%20Element

Oh, I see, it was actually my bracketing that was the problem! headsmack Thanks again @saqimtiaz :slight_smile:

I was reading the documentation tiddler for SetWidget just now than the last posts appeared in forum and I’ve got confused by the usage of select as well.

Before getting to the examples part, it looks like select is just an additional constraint when filter exists. But in this particular example it does not. Is this why you said it is not necessary here?

As for explicitly using select="0" being a good practice, is this more for achieving mental consistency with the way filters generally work (as in only the first item is usually returned)?

Correct, however I wanted to highlight it since that may have been a simplified example derived from a more complex real world use case where it might be relevant.

When using a filter with the set widget to assign a variable, it is a common pitfall to not realize that the widget is designed for working with title lists and will always return a title list from a filter evaluation even if that list is one item long. So your variable might be "[[Hello World]]" rather than Hello World unless you specify that you want to return a single value.

So the best practice is to always use select=“0” when intending to return a single item from the evaluation of a filter provided to the filter attribute to the set widget.

I am away from my desk, hopefully this is coherent enough to be helpful.

3 Likes

This is very coherent, and you are correct that the real world example does include filtering, so I’m glad you’ve clarified. :slightly_smiling_face: