How to decode some information encoded with prefixes and suffixes in a list, maintaining the list structure (first character and last three characters)

Coincidentally inspired by a filter I asked for in a recent thread, I had some inspiration for creating some convenient templates/models. (At the moment the application I have in mind for these templates is to manage which fields are “recommended” in the tiddler editor based on the selected template)

However, I would like to know if it is possible to do something like this:
I want to encode into a tiddler field that will be used as template a list of fields that will appear ready for use in the tiddler that has that template.

The list, in a field named model-field-list i will have a list (formatted like a title list) that would look something like this:
1captionES1 [[1my fieldES1]] 2colorES2

Encoded in this list I have these informations about the fields:

  1. The relative position in the editor with regard to the “text” field (I will create a tiddler tagged with $:/tags/EditTemplate to manage this later)
    1captionES1 (position “1” - info encoded in the first character of the element - prefix)

  2. The name of the “suggested” field

  3. The style of the editor (the template through which the field editor will be displayed: a multi line editor, a single line editor, one with 2 $radio - yes and no… etc.)
    1captionES1 (E-ditor S-tyle n1 - Info encoded in the last three characters of the element - suffix)

Can I decode this info in three variables? (or two variables - btw I don’t know if the word variable is the right one, but I hope you understand what I mean)
The relative position to the text field is not so important and I think can be managed easly, with a simple filter to filter out the elements with prefix “2” in the first place and then another to filter out the "1"s.
I don’t know how to proceed with the other encoded informations: the name and the style. I know there are some “suffix & co.” operators but I’m lost.

In the template/model tiddler editor there will be a manager for this model-field-list list
-A element builder: a radio to select either 1 or 2 a textbox to enter the field names and a dropdown for the style.
-And a drag and drop to sort this list (but this will be the last thing)
So the list does not have to be managed manually and the template can be changed easily and also edited easily.

I won’t explain in detail the functioning of this “template mechanism” in detail because I don’t want to take up too much of your time, but if you’re interested, ask me and I will tell you about it.

In short for those interested:

Each tiddler will have a “template” field that can be populated with a tiddler’s name.

This tiddler (the template tiddler) will have inside an easily editable list of fields and the relative editor styles which will then be “suggested” or “preselected” in the tiddler that has that template.

The mechanism is this:
in a tiddler tagged $:/tags/EditTemplate I have something like this:

\whitespace trim
<$list filter="[{!!model}get[model-field-list]enlist-input[]]" variable="currentModelField" template="Edit-template-A">

That is, from the tiddler that I am editing I look for its template: {!!model} Then I get the model’s field model-field-list that contains the list of fields I want to be suggested in the editor.
This list will have its variable currentModelField because currentTiddler is needed to point to the tiddler that is being edited later.
Then in the tiddler Edit-template-A I will have something like this:

<td class="tc-edit-field-value">
<$edit-text placeholder=<<currentModelField>> class="tc-edit-typeeditor tc-edit-texteditor tc-popup-handle" field=<<currentModelField>>/>
<td class="tc-edit-field-remove">
<$button tooltip="Delete" class='tc-btn-invisible tc-btn-icon'>
<$action-deletefield $field=<<currentModelField>>/>

This first test works. (It is only a test and works only with a list of field names withut encoding)
But I cannot encode yet the position and the style of the editor.

  • What I think I need to do now is:

I need to take the elements from the list <<currentModelField>>: 1captionES1 [[1my fieldES1]] 2colorES2

And I need to make them become something like: (Let’s ignore atm the prefix “1”)
<<FieldName>> + <<EditorStyle>>
FieldName will then be used to point to the right field, and EditorStyle will be then used to point to the right template. If I can decode the information I think I could make it work. (Not 100% sure, but I am fairly confident in this)

In any case, if something nice comes up I will share it with you. :wink:

Not sure exactly how you are going to use this. There is probably some way to do it using regular expressions, but it’s much easier if you structure your fields with some sort of separator (like a hyphen) and then split them –

<$list filter="1-caption-ES1 [[1-my field-ES1]] 2-color-ES2"
 n1={{{[<currentTiddler>split[-]!is[blank]nth[1]] }}}
 n2={{{[<currentTiddler>split[-]!is[blank]nth[2]] }}}
 n3={{{[<currentTiddler>split[-]!is[blank]nth[3]] }}}
<<n1>> | <<n2>> | <<n3>> <br/>



I feel like overall this method will be fragile. It might be better to put your field sets into their own field definition tiddler, and reference them there.

Thanks, now I see what I can do with the information you gave me. :+1: (It’s working surprisingly well)

Can I ask you what you mean?