How can I use match operator to transclude different tiddler types?

I’m trying to use a different prefix depending on the tiddler that is to be transcluded. But, can’t really figure out how to get the match operator to work properly. Although, the last match case is working properly.

This is what I have tried:

<$list filter="[<currentTiddler>fields[]prefix[cast-list]]" variable="cast">
  <table>
    <$list filter="<cast> [match[!!]]">
      <tr><$transclude tiddler={{{ [<currentTiddler>get<cast>addprefix[$:/head/]] }}}/></tr>
    </$list>
    <$list filter="<cast> [match[:]]">
      <tr><$transclude tiddler={{{ [<currentTiddler>get<cast>addprefix[$:/block/]] }}}/></tr>
    </$list>
    <$list filter="<cast> [!match[!!]] +[!match[:]]">
      <tr>
        <$transclude tiddler={{{ [<currentTiddler>get<cast>split[@]nth[1]addprefix[$:/cast/]] }}}/>
        <$transclude tiddler={{{ [<currentTiddler>get<cast>split[@]nth[2]addprefix[$:/role/]] }}}/>
      </tr>
    </$list>
  </table>
</$list>

This is tricky to answer without understanding what the contents of the cast-list* fields look like.

Are you sure you want to match the entire value of the variable cast, which is what the match[] operator does? Or are you checking for a prefix of the cast variable, in which case you would want the prefix[] operator?

Since we know the field names are prefixed with cast-list they will never match !! or :. Do you perhaps want to use the removeprefix[] operator in that outermost list widget?

If none of this addresses your problem, please post an example tiddler.

Here is a screenshot of the fields:


I was trying to do a partial match. Although, I would need to remove the !! and :, before adding the prefix. It’s just a way of letting the code know which type of prefix to add.

The variable cast will contain values (00), (01), (02), etc. Right? So cast will never match : or !! either partially or entirely.

Not seeing the tiddler, but are there also plain fields like: (00), (01), (02) … ?

This might be closer to what you want, it is really hard to say without seeing all the tiddlers this depends on. What do the names of the transcluded tiddlers look like?


<$list filter="[<currentTiddler>fields[]prefix[cast-list]]" variable="cast">
  <table>
    <$list filter="[<currentTiddler>get<cast>removeprefix[!!]]">
<tr><$transclude tiddler={{{ [<currentTiddler>addprefix[$:/head/]] }}}/></tr>
    </$list>
    <$list filter="[<currentTiddler>get<cast>removeprefix[:]]">
      <tr><$transclude tiddler={{{ [<currentTiddler>addprefix[$:/block/]] }}}/></tr>
    </$list>
    <$list filter="[<currentTiddler>get<cast>!prefix[!!]!prefix[:]]">
      <tr>
        <$transclude tiddler={{{ [<currentTiddler>split[@]nth[1]addprefix[$:/cast/]] }}}/>
        <$text tiddler={{{ [<currentTiddler>split[@]nth[2]addprefix[$:/role/]] }}}/>
      </tr>
    </$list>
  </table>
</$list>

Key things to note:

  • match[] matches entire strings
  • removeprefix[] matches the indicated prefix while only allowing the titles that match to pass through
  • fields[] returns the field names, you probably want to work with their values.

That did put me on the right path this working properly:

<table>
	<$list filter="[<currentTiddler>fields[]prefix[cast-list]]" variable="cast">
  	<$list filter="[<currentTiddler>get<cast>removeprefix[!!]]" variable="head">
			<tr><$transclude tiddler={{{ [<head>addprefix[$:/head/]] }}}/></tr>			
		</$list>
		<$list filter="[<currentTiddler>get<cast>removeprefix[:]]" variable="block">
			<tr><$transclude tiddler={{{ [<block>addprefix[$:/block/]] }}}/></tr>			
		</$list>
		<$list filter="[<currentTiddler>get<cast>!prefix[!!]!prefix[:]]" variable="actor">
			<tr>
				<$transclude tiddler={{{ [<currentTiddler>get<cast>split[@]nth[1]addprefix[$:/cast/]] }}}/>
				<$transclude tiddler={{{ [<currentTiddler>get<cast>split[@]nth[2]addprefix[$:/role/]] }}}/>
			</tr>
		</$list>
	</$list>
</table>

Thanks for the help, and all the feedback!

The field names will be numbered, but the values will not be numbered in that way. I am used to JavaScript where .match("value")does a partial match. I thought that maybe the match operator might work in the same way. Thanks for the feedback!

The prefix or suffix operator act as a partial match with the prefix or suffix, you can also use the search operator and or is regular expressions support.

If you need to use Javascript for anything in TiddlyWiki, you have possibly missed the tiddlywiki way of doing things.