Sort by First of list, correction needed

Hi TW-Experts,

I try to sort a list by the first entry of another list.
This here is working well:
<$list filter="[tag<selector>sort[caption]]" variable="subfield">
But this here has only the first value as result and not the sorted list
<$list filter="[tag<selector>sort[list[fields]first[]]" variable="subfield">

Here is the complete code where it comes from.
It is a procedure that is generating a table from fields and the tiddlers are selected by a tag.
May be that is helpful to explain my problem.

Any help is appreciated and welcome
Thank you
Stefan

\procedure tids2table(selector, fields)
<$let
    fields={{{ [<fields>!match[]] ~[[info/db_tables]get<selector>] }}}
>

<table>
<tr>
<th></th>
<$list filter="[enlist<fields>]" ><th><<currentTiddler>></th></$list><br/>
</tr>
<!--<$list filter="[tag<selector>sort[list[fields]first[]]" variable="subfield">
-->
<$list filter="[tag<selector>sort[caption]]" variable="subfield">
 <tr>
    <td>
      <$link to={{{ [<subfield>] }}} >
       Edit
      </$link>
    </td>
  <$list filter="[enlist<fields>]" join=<<separator>> variable="field">
    <td>
       <% if [<subfield>get<field>is[tiddler]] %>
          <$link to = {{{ [<subfield>get<field>] }}} />
       <% else %>
          <$text text = {{{ [<subfield>get<field>] }}} />
       <% endif %>
	</td>
<!--
    </td>
-->
  </$list>
 </tr>
</$list>
</table>
</$let>
\end

You can’t “nest” filter syntax within another filter operator’s parameter. Thus, sort[list[fields]first[]] is not valid syntax.

To work around this limitation you can calculate the parameter value first, and then reference it using a variable, like this:

<$let thisfield={{{ [list[fields]first[]] }}}>
<$list filter="[tag<selector>sort<thisfield>]" variable="subfield">

-e

1 Like

addendum:

Based on the code you posted, I think you might want to use enlist<fields> rather than list[fields], like this:

<$let thisfield={{{ [enlist<fields>first[]] }}}>
<$list filter="[tag<selector>sort<thisfield>]" variable="subfield">

-e