Is it possible to add text to a existing tiddler without overwriting the existing content using action setfield widget. If any other widget can do this, then it fine. Just that I experimented with setfield only which was not working.
You have to grab the text of the existing field, append (or prepend) your additional text, and then write-over the field.
Example that writes over text field of “HelloThere” with your additional text –
\define appendmore()
<$action-setfield $tiddler="HelloThere" text={{{[[HelloThere]get[text]addsuffix{$:/temp/moretext}]}}} />
\end
<$edit-text tiddler="$:/temp/moretext" tag="input" size=40 />
<$button actions=<<appendmore>>>Append text</$button>
\function filepath-butlast()
[<actionTiddler>split[/]butlast[]join[,]]
\end
\function filepath-second-last()
[<filepath-butlast>split[,]last[]]
\end
\procedure append-image-widget()
<$image source=<<createTiddler-title>> />
\end
\procedure droppable-image-actions1()
<$action-setfield $tiddler=<<actionTiddler>> $field="images" $value={{{ [<actionTiddler>split[/]last[]addprefix[/]addprefix<filepath-second-last>addprefix[./files/]] }}}/>
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>>/>
<$action-setfield $tiddler=<<currentTiddler>> text={{{[<currentTiddler>get[text]addsuffix<append-image-widget>] }}} />
<$action-deletetiddler $tiddler=<<actionTiddler>>/>
</$action-createtiddler>
\end
<$droppable actions=<<droppable-image-actions1>>>
</$droppable>
@Mark_S I was trying a modified version of [tw5] TiddlyWiki: Drag and drop image link to create tiddler with _canonical_uri link to the image by @Charlie_Veniot
I wanted to create an image tiddler for a local file using his method and simultaneously add that image tiddler into my currentTiddler
text field. I was trying to use the createTiddler-title
variable, but it doesn’t seem to work. What am I doing wrong ?
You’ve closed the $action-createtiddler widget in this line…
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>>/>
^
… which means <<createTiddler-title>>
is undefined where you’re using it. Try it with >
instead of the self-closing />
:
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>> >
I’m not entirely sure what the objective is here, but this code should nudge it a little along the way.
You closed the $action-createtiddler prematurely with \>
So the contents of the tag weren’t able to see the variables.
Also, I don’t think you can insert a procedure as if it were a variable – it will just generate the literal text. But you can do that with a function. (these names — a function is actually a filter, but I digress)
So I turned your procedure into a function. Now it drops the content of the variable. You probably want it to do something slightly different. Like have the name wrapped in an image tag? Not sure.
I also added a visible target for the drop.
\function filepath-butlast()
[<actionTiddler>split[/]butlast[]join[,]]
\end
\function filepath-second-last()
[<filepath-butlast>split[,]last[]]
\end
\function append-image-widget()
[<createTiddler-title>]
\end
\procedure droppable-image-actions1()
<$action-setfield $tiddler=<<actionTiddler>> $field="images" $value={{{ [<actionTiddler>split[/]last[]addprefix[/]addprefix<filepath-second-last>addprefix[./files/]] }}}/>
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>>>
<$action-setfield $tiddler=<<createTiddler-title>> text={{{[<createTiddler-title>get[text]addsuffix<append-image-widget>] }}} />
<$action-deletetiddler $tiddler=<<actionTiddler>>/>
</$action-createtiddler>
\end
<$droppable actions=<<droppable-image-actions1>>>DROP HERE
</$droppable>
Thank you @Mark_S and @etardiff for helping out in the right direction. Here is the code I tried.
\function filepath-parts()
[<actionTiddler>split[/]format:titlelist[]]
\end
\function filepath-butlast()
[<actionTiddler>split[/]butlast[]join[,]]
\end
\function filepath-second-last()
[<filepath-butlast>split[,]last[]]
\end
\function img-tid-title()
[<createTiddler-title>]
\end
\procedure droppable-image-actions1()
<$action-setfield $tiddler=<<actionTiddler>> $field="text" $value=""/>
<$action-setfield $tiddler=<<actionTiddler>> $field="images" $value={{{ [<actionTiddler>split[/]last[]addprefix[/]addprefix<filepath-second-last>addprefix[./files/]] }}}/>
<$let
img-widget=`<$image source="$(img-tid-title)$"/>`
>
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>> >
<$action-setfield $tiddler=<<currentTiddler>> text={{{[<currentTiddler>get[text]addsuffix<img-widget>] }}} />
</$let>
</$action-createtiddler>
\end
I am getting the image widget without the source value like this in the currentTiddler
<$image source=""/>
Also two image tiddlers are getting created.
Why this happens
This version creates image tag correctly. But it puts it into the tiddler where the dropping happens. I don’t think that is what you want, but I’m not sure where you meant it to end up.
\function filepath-parts()
[<actionTiddler>split[/]format:titlelist[]]
\end
\function filepath-butlast()
[<actionTiddler>split[/]butlast[]join[,]]
\end
\function filepath-second-last()
[<filepath-butlast>split[,]last[]]
\end
\function img-tid-title()
[<createTiddler-title>]
\end
\procedure droppable-image-actions1()
<$action-setfield $tiddler=<<actionTiddler>> $field="text" $value=""/>
<$action-setfield $tiddler=<<actionTiddler>> $field="images" $value={{{ [<actionTiddler>split[/]last[]addprefix[/]addprefix<filepath-second-last>addprefix[./files/]] }}}/>
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>> >
<$let
img-widget={{{[[<$image source="]addsuffix<createTiddler-title>addsuffix["/>]]}}}
>
<$action-setfield $tiddler=<<currentTiddler>> text={{{[<currentTiddler>get[text]addsuffix<img-widget>] }}} />
</$let>
</$action-createtiddler>
\end
<$droppable actions=<<droppable-image-actions1>>>DROP HERE
</$droppable>
Thank you @Mark_S . Its working now and image widget is getting added to the currentTiddler as expected (I have added a dropzone for each tiddler via template)
Two more issues to be resolved now
- I am getting an extra image tiddler with name like this
file:///C:/Users/Arun%20C%20Babu/OneDrive/my-wikis/files/neuro-rad/antinmdar-encephalitis_tweet_drbejoy200220241105131224031.png
.Which part of the code is causing this duplication of image tiddlers - How to add a line break for each addition to the text field using this dropzone
What do your image tiddlers names look like before they are dragged, and what image name do you want to appear in the images field? An example tiddler would help.
Your current drag/drop code will erase your original image, and I’m not sure that that is necessary or safe.
There is a tweak needed to handle drop targets with empty contents.
antinmdar-encephalitis_tweet_drbejoy200220241105131224031.png
this is sample filename.
file:///C:/Users/Arun%20C%20Babu/OneDrive/my-wikis/files/neuro-rad/antinmdar-encephalitis_tweet_drbejoy200220241105131224031.png
this is the filepath of the same image.
Two image tiddlers are getting created
- one with title
antinmdar-encephalitis_tweet_drbejoy200220241105131224031.png
- other as title
file:///C:/Users/Arun%20C%20Babu/OneDrive/my-wikis/files/neuro-rad/antinmdar-encephalitis_tweet_drbejoy200220241105131224031.png
.
Both of them have a field called images with the field value as ./files/neuro-rad/antinmdar-encephalitis_tweet_drbejoy200220241105131224031.png
.
I use a custom image widget to display these images. Field value which I want is correct.
I don’t want the tiddler with title file:///C:/Users/Arun%20C%20Babu/OneDrive/my-wikis/files/neuro-rad/antinmdar-encephalitis_tweet_drbejoy200220241105131224031.png
But isn’t this the tiddler that you are dragging and dropping? So it would be the original.
If it’s not, then what is being dragged/dropped?
I note that in your code attempt above the delete-tiddler widget was removed.
This code fixes a bug where the image tag is not inserted if the target tiddler isn’t empty. It also re-arranges the code so as not to erase the text field of the original.
\function filepath-parts()
[<actionTiddler>split[/]format:titlelist[]]
\end
\function filepath-butlast()
[<actionTiddler>split[/]butlast[]join[,]]
\end
\function filepath-second-last()
[<filepath-butlast>split[,]last[]]
\end
\function img-tid-title()
[<createTiddler-title>]
\end
\procedure droppable-image-actions1()
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>> >
<$let
img-widget={{{[[<$image source="]addsuffix<createTiddler-title>addsuffix["/>]]}}}
>
<$action-setfield $tiddler=<<createTiddler-title>>
text=""
images={{{ [<actionTiddler>split[/]last[]addprefix[/]addprefix<filepath-second-last>addprefix[./files/]] }}}/>
<$action-setfield $tiddler=<<currentTiddler>> text={{{[<currentTiddler>get[text]addsuffix<img-widget>else<img-widget>] }}} />
</$let>
</$action-createtiddler>
\end
<$droppable actions=<<droppable-image-actions1>>>DROP HERE
</$droppable>
This settles all issues.
One last doubt, can we add a line break prior to appended image widget
This adds a linefeed. You can duplicate addsuffix<lf>
to add more line feeds.
\function filepath-parts()
[<actionTiddler>split[/]format:titlelist[]]
\end
\function filepath-butlast()
[<actionTiddler>split[/]butlast[]join[,]]
\end
\function filepath-second-last()
[<filepath-butlast>split[,]last[]]
\end
\function img-tid-title()
[<createTiddler-title>]
\end
\procedure droppable-image-actions1()
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>> >
<$let
img-widget={{{[[<$image source="]addsuffix<createTiddler-title>addsuffix["/>]]}}}
lf="""
"""
>
<$action-setfield $tiddler=<<createTiddler-title>>
text=""
images={{{ [<actionTiddler>split[/]last[]addprefix[/]addprefix<filepath-second-last>addprefix[./files/]] }}}/>
<$action-setfield $tiddler=<<currentTiddler>> text={{{[<currentTiddler>get[text]addsuffix<lf>addsuffix<img-widget>else<img-widget>] }}} />
</$let>
</$action-createtiddler>
\end
<$droppable actions=<<droppable-image-actions1>>>DROP HERE
</$droppable>
lf="""
"""
is assigning a literal newline to the variable lf
. This could also be accomplished by setting
lf={{{ [charcode[10]] }}}
which doesn’t rely upon having an actual newline in the assignment.
This variable is then used in the text={{{ ...addsuffix<lf>... }}}
filtered transclusion to actually add the newline to the text field of the target tiddler.
-e