How to copy tiddler data pieces between fields and tags?

I have two input values: TAG_VALUE and FIELD_NAME, and two complementary use cases:

  1. For all tiddlers in a wiki that have a TAG_VALUE tag, add a field FIELD_NAME and set its value to TAG_VALUE, but only if field FIELD_NAME doesn’t exist, or exists, but has an empty value (because I don’t want to accidentally overwrite existing data)

  2. The opposite of 1. - for all tiddlers that have a field FIELD_NAME with a non-empty FIELD_VALUE, create a FIELD_VALUE tag.

Is this possible to be done with any existing plugin? My first thought was Tiddler Commander, but it seems to separate management of tags and fields into different tabs.

I’d like this for being able to convert between vanilla ToC which uses tags, and tocP style ToC, which uses parent field to store relationships between tiddlers

Give this a try:

<$edit-text tiddler="$:/temp/TagValue" tag=input placeholder="enter tag value"/>
<$edit-text tiddler="$:/temp/FieldName" tag=input placeholder="enter field name"/>
<$let thistag={{$:/temp/TagValue}} thisfield={{$:/temp/FieldName}}>

Use-case #1:
<$button> move <<thistag>> tag to <<thisfield>> field
<$list filter="[tag<thistag>!has<thisfield>]">
   <$action-setfield $field=<<thisfield>> $value=<<thistag>>/>
   <$action-listops $tags="-[<thistag>]"/>
</$list>
</$button>

Use-case #2:
<$button> move <<thisfield>> field to <<thistag>> tag
<$list filter="[has<thisfield>]">
   <$action-setfield $field=<<thisfield>>/>
   <$action-listops $tags="[<thistag>]"/>
</$list>
</$button>

Notes:

  • For flexibility, we enter the desired tag value and field name and then set variables thistag and thisfield to the those values. This makes it easy to change the tag value and field name without having to edit the code each time.
  • Use-case #1:
    • The $list filter finds all non-shadow tiddlers tagged with <thistag> that do not have a <thisfield> field or have a <thisfield> field that is empty.
    • For each tiddler it finds, it creates a <<thisfield>> field with the specified <<thistag>> value and removes the <thistag> tag.
  • Use-case #2:
    • The $list filter finds all non-shadow tiddlers that have a non-blank <thisfield> field.
    • For each tiddler it finds, it removes the <<thisfield>> field and adds the <thistag> tag.
  • Note that within the filter syntax, single angle brackets are used to surround the variable references. For all other variable references (i.e., as display text or widget parameter values) use doubled angle brackets around the variable references.

enjoy,
-e

The poltergeist again. I tested with tag +tag1. Use case #1 results with field with value +tag1 getting created, but tiddlers get a new tag1 tag.

It is interesting that the poltergeist is gone again for tag +tag1 tag2 (this is a single multiword tag, prefixed with + as well).

The cause is the same as the last time we saw this issue… the $action-listops widget treats the $tags parameter as a subfilter, so the leading + on the tag value gets interpreted as a filter run prefix instead of part of the tag value itself.

The solution is also the same as the last time… the $action-listops widget needs to use the $filter parameter like this:

Use -case #1:

<$action-listops $field="tags" $filter="[enlist{!!tags}] -[<thistag>]"/>

Use-case #2:

<$action-listops $field="tags" $filter="[enlist{!!tags}] [<thistag>]"/>

-e

Thank you.

Now that it works, I wonder if the task that gets solved is generic enough to hope that this can get bundled into Commander plugin (easier for me, because I won’t have to maintain this code snippet in my wikis), or if it wouldn’t be a good idea, because it breaks the principle of managing tags and fields separately, like the Commander plugin currently does.

1 Like