Hello all,
I want to drag plain text (sometimes HTML) vocabulary term-definition to create a tiddler with term as title and definition as content. If the tiddler exists, the new content is appended to the existing tiddler otherwise create new. (keeping only the text. )
My code creates a new tiddler the first time. On second try it creates yet another tiddler -with the same name. What am I doing wrong?
\define vocabSplitPattern() [¦|\/]
\define droppable-text-actions()
/* use vocabSplitPattern() [¦|\/] to split at ¦ or / */
<$wikify name=import-text text=<<actionTiddler>>>
<$vars newTitle={{{ [<import-text>splitregexp<vocabSplitPattern>first[]] }}}
newDefn={{{ [<import-text>splitregexp<vocabSplitPattern>last[]] }}}
lf="""
<hr/>
""">
<!-- If tiddler exists, append new definition -->
<$list filter="[<newTitle>has[text]]" variable="oldText">
<$vars oldText={{{ [<currentTiddler>get[text]] }}} >
<$action-setfield $tiddler=<<currentTiddler>> text={{{ [<newDefn>addsuffix<oldText>] }}} />
<$action-navigate $to=<<currentTiddler>>/>
</$action-setfield>
</$vars>
</$list>
<!-- If tiddler does not exist, create it -->
<$list filter="[<newTitle>!has[title] ]">
<$action-createtiddler $basetitle=<<newTitle>> $template=<<actionTiddler>> text=<<newDefn>> tags="vocab" >
<$action-navigate $to=<<createTiddler-title>>/>
</$action-createtiddler>
</$list>
</$vars>
</$wikify>
\end
<$droppable actions=<<droppable-text-actions>>>
<$button style="width:10em;height:3em;">Drop vocab here</$button>
</$droppable>
Test data–
banana ¦ fruit i eat . hmmm.
banana / another line