Exporting and importing fields

Hi,

I have a Tiddler called TiddlerA with 5 fields and I want to import these fields to another Tiddler called TiddlerB, such that,
if I change the values of any fields in TiddlerA should reflect on TiddlerB.

How can I achieve this in Tiddlywiki?

Thanks

You can transcode the fields like this:

{{TiddlerA!!field}}

Repeat

okay, but how can I update the if I change the value of the field in the TiddlerA, and get reflected in TiddlerB.
And I want to set the field value, not just displaying.
Meaning that,
{{TiddlerA!!field}} will display the value, but I need field2 = {{TiddlerA!!field}}, field2 should get this value, can’t use button actions to trigger it. is there any other way?

That’s not possible at the moment. Tiddlers do not inherit fields from other tiddlers, without using templates to render them.

If tiddlers are transcluded from A into B using a template it will be possible to render fields from A if no such field exists in B. If a field exists in B it will be shown instead. – That’s possible.

Great insight. Thanks for the update

I started a long thread about such a possibility. The result was that while this might have been an interesting architecture to start TW with, it was far too late to introduce it. We could make our own convention for inheritance and create tools parallel to built-in ones (such as the get operator and the transclude widget) to work with it. But it would be a major understanding.

Thanks for the guidance. That would be amazing to have that feature.

In cases like this, I’d encourage you to share not just the micro-behavior you think you want, but what you’re up to with your wiki solution — often there’s a better way to approach your task, once the information structure and/or workflow needs are clearer.

In particular, I’m curious how and why you’d need what sounds like a hybrid between just transcluding the value (as established in another tiddler) and copying it… Do you need something like: show the value in the other tiddler, until and unless it gets overridden with its own specified value in this-here tiddler? If so, then there may be conditional wikitext solutions that display what you need (in the default case / “mirror the other value” situation) even when there’s no actual field value present in the newer tiddler…

1 Like

I want to have overridden behavior between two tiddlers with their some of the fields. But I need to take the lastest value which is updated recently, kind of synchronization

In this kind of case, I suspect you actually want a third place to hold the update-sensitive value, because the value is logically coming from something other than the nature of the one or the other object. It’s coming from something like… an update event, right? Then multiple tiddlers can make use of this relevant information, which is not logically within any one of them. Yes?

Note, fields as they currently work don’t track their update stamp separately from the tiddler they’re in. If they did — and there may be plugins that do so, if I recall correctly — then you could harness such field-specific metadata.

In my case 2 tiddlers are using 3 fields , and it can be updated from those 2 fields. If I update field1 from TiddlerA , then if I open TiddlerB, it should have the lastest value from the TiddlerA’s field 1. Kind of transmitting information between 2 tiddlers.
Yes , I have some logical Operations in between

My quick thought is: something that can be updated from either of the two tiddlers is not actually a field OF those tiddlers (isn’t best modeled/understood that way). It may be a hidden tiddler. We’d want to know more about the data structure…

If the “update a field” is triggered by input to an $edit-text widget, then you could use the inputActions=... parameter to automatically sync the value of that field in other tiddlers.

Something like this:

\define syncField(fieldname)
<$list filter="[has:field<__fieldname__>]">
<$action-setfield $field=<<__fieldname__>> $value=<<actionValue>>/>
</$list>
\end

<$edit-text field="somefield" inputActions="<<syncField somefield>>"/>

Notes:

  • The syncField() macro finds all tiddlers that have the specified fieldname and then sets that field to the current actionValue variable that is automatically provided by the inputActions=... handling
  • You could put the syncField() macro definition into a separate tiddler, tagged with $:/tags/Global, so that it will be available for use in any other tiddler without having to define it each time.
  • If you want to limit the sync action to only specific named tiddlers, you could change the $list widget to something like:
<$list filter="[[TiddlerA]] [[TiddlerB]] [[TiddlerC]]">

-e

2 Likes

nice to know,
what if I have in TiddlerA, 2 fields that have an edit option?
And I have used those 2 fields in TiddlerB.

\define syncField(fieldname)
<$list filter="[has:field<__fieldname__>]">
<$action-setfield $field=<<__fieldname__>>
$value={{TiddlerA!!__fieldname__}}
/>
</$list>
\end
<$edit-text tag="input" size="50" field="field1" 
 inputActions="<<syncField field1>>"
/>

<$edit-text tag="input" size="50" field="field2" 
 inputActions="<<syncField field2>>"
/>

It didn’t work for me,
I tried with:

$value={{TiddlerA!!__fieldname__}}

and

$value={{TiddlerA!!fieldname}}

Nothing worked for me. I ran into an infinite loop, and I could not type in the input box.

But when I tried:

$value={{TiddlerA!!field1}}

then in TiddlerB, the field1 got the updated value.
In my case I have nearly 10-15 input boxes, should I write individual macros for each edit option?

How do I solve this?

The syncField() macro I provided does not depend upon a reference to the tiddlername!!fieldname of the “source” tiddler. Instead, it uses <<actionValue>>, which automatically gets the value from the $edit-text widget that is triggering the call to <<syncField fieldname>>. Thus, you can use the same, general-purpose syncField() macro to sync values from ANY source tiddler for all corresponding fields in other “target” tiddlers. Put this general-purpose syncField() macro into a separate tiddler (e.g., “SyncFields”) tagged with $:/tags/Global.

\define syncField(fieldname)
<$list filter="[has:field<__fieldname__>]">
<$action-setfield $field=<<__fieldname__>> $value=<<actionValue>>/>
</$list>
\end

This allows the macro to be called from any tiddler, without needing to define it each time you want to use it.

Then, in each tiddler that you want input to be sync’ed with other tiddlers, all you need to write is:

<$edit-text tag="input" size="50" field="field1" inputActions="<<syncField field1>>"/>
<$edit-text tag="input" size="50" field="field2" inputActions="<<syncField field2>>"/>

-e

1 Like

See docs: https://tiddlywiki.com/#EditTextWidget

Great insight, it worked. Thanks for the support

Thanks for the insight