String operation on value of variable

Hi,
I want to list certain fieldnames and fieldvalues within the body of the corresponding current tiddler. I am naming these fieldnames starting with ‘kp_’ for filtering which fields to show and want to remove this prefix when displayed in body of tiddler.
I thought of using removeprefix on <<fieldname>> , but could not figure out the syntax.
Thanks, KP

<$list filter="[<currentTiddler>fields[]prefix[kp_]]" variable=fieldname>
    <$list filter="[<currentTiddler>get<fieldname>]" variable=field-value>
        <tr><td><<fieldname>></td><td><<field-value>></td></tr>
      </$list>
</$list>

Hi @KPtko

You can use a function to remove the “kp_” prefix like this:

\function no.kp_() [<fieldname>removeprefix[kp_]]
<$list filter="[<currentTiddler>fields[]prefix[kp_]]" variable=fieldname>
    <$list filter="[<currentTiddler>get<fieldname>]" variable=field-value>
        <tr><td><<no.kp_>></td><td><<field-value>></td></tr>
      </$list>
</$list>

Fred

1 Like

removeprefix should do what you want:

title: Nantucket
tags: 
caption: Random Limerick
another-field: with a random value
kp_line1: There once was a man from Nantucket
kp_line2: Who kept all his cash in a bucket
kp_line3: But his daughter named Nan
kp_line4: Ran away with a man
kp_line5: And as for the bucket -- Nantucket
xxx-line6: Random other lines don't show up.

<table><tr><th>field</th><th>value</th></tr>
<$list filter="[<currentTiddler>fields[]prefix[kp_]]" variable=fieldname>
    <$list filter="[<currentTiddler>get<fieldname>]" variable=field-value>
        <tr><td><$text text={{{ [<fieldname>removeprefix[kp_]] }}} /></td><td><<field-value>></td></tr>
      </$list>
</$list>
</table>

Result

field value
line1 There once was a man from Nantucket
line2 Who kept all his cash in a bucket
line3 But his daughter named Nan
line4 Ran away with a man
line5 And as for the bucket – Nantucket

Nantucket.json (824 Bytes)

@tw-FRed , @Scott_Sauyet Thanks.

Rookie mistake - I was missing the {{{ }}} around the $text.