[TW5] How do I add/remove tags from a tiddler inside a JavaScript plugin?

60 views
Skip to first unread message

Devin Weaver

unread,
Jan 21, 2016, 12:00:42 PM1/21/16
to TiddlyWikiDev
I have a plugin that takes a tiddler which has a known tag and I want to remove that tag from the tiddler.

I found out the hard way that tiddler.fields.tags is frozen so I can not filter or slice it.

Is there a function in the core that will remove / add tags to a tiddler?

Felix Küppers

unread,
Jan 21, 2016, 12:31:43 PM1/21/16
to tiddly...@googlegroups.com
Hi Devin,

you need to create a new tiddler based on the old tiddler and also override the "tags" field, also you need to clone the array to work with it using slice. The $tw.Tiddler() constructor accepts tiddler objects as arguments and "hashmaps" so just do the following (off the top of my head):

var copyOfArray = myOldTiddlerWhichIsFrozen.fields.tags.slice(0)

do your array stuff and then:

var fields = {
  tags: myChangedArray
};

var mod = $tw.Tiddler(myOldTiddlerWhichIsFrozen, fields);

then add this tiddler to the store using $tw.wiki.addTiddler(mod)

-Felix
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/6a8165b6-d528-41b3-9c5c-0601df4990a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Devin Weaver

unread,
Jan 21, 2016, 1:11:42 PM1/21/16
to TiddlyWikiDev
Add then Remove. Cool thanks. I though there was something like that.
Reply all
Reply to author
Forward
0 new messages