How does one handle dynamic content?

120 views
Skip to first unread message

Tristan Kohl

unread,
Oct 29, 2018, 10:45:59 AM10/29/18
to TiddlyWiki
Hey guys,

I have an issue with my current project. I am not sure how one would tackle this problem so I hope one of you could help me:

I have a tiddler representing a person which gets rendered through a template to display some fields. After creation there are only three fields: forename, surname and birthday. However in my template I would like to have a edit-text widget by what I would add contact informations to that contact. I could create a new tiddler for every phone number, email etc. but since those values are tightly coupled to a person I think it would be easier to manage if I put those inside the person tiddler as they are no longer useful if I delete this person (I would put them in the same table in a relational database as well).

But here comes my current problem into play as I do not know how to store an arbitrary amount of contact informations inside a field so I can nicely iterate over them in the template for display. My second idea was to make the person tiddler a dictionary tiddler and pass it through a template upon request but I have no idea how one would do this and if that would even be possible.

TL;DR;
How do I store an arbitrary amount of values inside a field (JSON maybe?) and how to iterate over them? Is there a better alternative?

Mark S.

unread,
Oct 29, 2018, 12:04:48 PM10/29/18
to TiddlyWiki
I would avoid complicated structures like JSON, since the tools in TW won't let you work with them easily.  In most cases, it will be easier to use other tiddlers as if they formed the related table in a relational database.

I think you want each individual to have multiple contact structures. You could store these in separate tiddlers. (e.g. Person1-Contact1, Person1-Contact2). Then have a list field like "contacts" that stores the name of related contact structures:

contacts: [[Person1-Contact1]] [[Person1-Contact2]]

You could have a template for each person. And a contact Template. Your person template would call the contact template:

<$edit field="vorname" .... whatever else needs to be edited here ...>
<$list filter=[enlist{!!contacts}] >
{{||contactTemplate}}
</$list>

The contact template exposes fields like phone number:

Phone: <$edit-text field="phone1" size=20 tag="input"/>

Good luck!
-- Mark

Tristan Kohl

unread,
Oct 29, 2018, 12:16:22 PM10/29/18
to TiddlyWiki
Thanks, that sounds very promising, I almost made my peace with huge filtering all over the place :/. But how do I get those titles in my list field without overwriting those that are already there? And how do I manage deletion of say Person1-Contact2 which might be somewhere in the middle of that list?

Cheers,
Tristan

Mark S.

unread,
Oct 29, 2018, 1:14:12 PM10/29/18
to TiddlyWiki
The

ActionListopsWidget


can be used to add items to a list.

The delete widget can be used to delete tiddlers.

Your outer template (overall template) might look like:

<$vars person=<<currentTiddler>>>

<$list filter=[enlist{!!contacts}] >
{{||contactTemplate}}
</$list>
</$vars>

and the contact template might look like:

<$button>
<$action-deletetiddler $tiddler=<<currentTiddler>> />
<$action-listops $tiddler=<<person>> $field="contacts" $subfilter="+[remove<currentTiddler>]"/>
Delete <<currentTiddler>> which supports <<person>>
</$button>
Phone: <$edit-text tiddler=<<person>> field="phone1" size=20 tag="input"/>

Then a button would appear in each contact section allowing you to remove that tiddler and remove it's entry in the contact list.

HTH
-- Mark

Tristan Kohl

unread,
Oct 30, 2018, 6:51:43 AM10/30/18
to TiddlyWiki
Thank you, this might do the trick :)
Reply all
Reply to author
Forward
0 new messages