Hi @TW_Tones ,
After several attempt, I managed to solve the conditional statement see below
var excisionTitle = event.paramObject.title || this.wiki.generateNewTitle("New Excision");
switch(event.paramObject.type || "transclude") {
case "flashcard":
this.wiki.addTiddler(new $tw.Tiddler(
this.wiki.getCreationFields(),
this.wiki.getModificationFields(),
{
title: "Answer "+excisionTitle,
answer: operation.selection,
tags:"flashcard",
text: operation.selection + " [[Ref|"+editTiddlerTitle+"]]"
}
));
this.wiki.addTiddler(new $tw.Tiddler(
this.wiki.getCreationFields(),
this.wiki.getModificationFields(),
{
title: "Question "+excisionTitle,
text: "{{Answer " + excisionTitle + "||Flashcard template}} {{||Source template}}",
answer:editTiddlerTitle,
tags:"flashcard"
}
));
break;
case "transclude":
this.wiki.addTiddler(new $tw.Tiddler(
this.wiki.getCreationFields(),
this.wiki.getModificationFields(),
{
title: excisionTitle,
text: operation.selection,
tags: event.paramObject.tagnew === "yes" ? [editTiddlerTitle] : []
}
));
break;
case "link":
this.wiki.addTiddler(new $tw.Tiddler(
this.wiki.getCreationFields(),
this.wiki.getModificationFields(),
{
title: excisionTitle,
text: operation.selection,
tags: event.paramObject.tagnew === "yes" ? [editTiddlerTitle] : []
}
));
break;
case "macro":
this.wiki.addTiddler(new $tw.Tiddler(
this.wiki.getCreationFields(),
this.wiki.getModificationFields(),
{
title: excisionTitle,
text: operation.selection,
tags: event.paramObject.tagnew === "yes" ? [editTiddlerTitle] : []
}
));
break;
}
It gives a clickable flashcard option in excise menu so it will create new question and answer tiddler with predefined field and transclusion template. I will create another topic to show case how my flashcard solution works. Hope it can inspire people on making flashcard in TW.
But meanwhile I still need advice, perhaps someone can offer simplification on my code above. I need to use 4 times switch-case which makes the code ugly. Case link, case macro and case transclude has similar syntax, I think it can be simplified.