How to create button that allows you to choose between two templates

Hello Fred.

Yes, what you propose would work perfectly for me. I have been taking a look at the information you have indicated but I still don’t understand how I can do it. I don’t see an example of doing something similar.

I’ve tried the system’s More button and cloned it to play with it and understand what it does, but I haven’t been able to get it to show me a cloned H4 tiddler with a different label.

I’ve looked at the code and I understand some things, but most of them I have no idea what they do…

All the best.

This option seems the easiest to put into practice. Another way that I imagined could be done would be with Radio buttons, but it would be the same case that you told me before. You would first select the template and then run from the button.

All the best.

Hi @Xabrina

Here is an example for you: XabrinaExample.json (4.0 KB)

Please be aware that provided templates are all the same, only captions differ.

Fred

2 Likes

Hello Fred.

It’s just what I was trying to do!!! :partying_face:

I will take a good look at the code to understand it well and be able to use it on other occasions. It was a great detail that you commented on the code, it helps people like me a lot. :sweat_smile:

Thank you so much!!!

All the best.

Nice work @tw-FRed, You have inspired me to write some generic solutions for popups,

  • I will share one back here to meet the Original Request but that can also be reused in many ways. And with an explanation.
  • This suggests to me a library of code solutions for the intermediate level user so they can save time but also learn from the example would make a good resource.
2 Likes

Thank you, clever solution !
Is it possible to modify it a bit to have the same look for the popup menu than the one used for the tags ?
Capture d’écran 2023-10-16 à 10.01.58

1 Like

Keep in mind it may be best not to have such “buttons” look like tag pills, a partial use of this class goes someway to your request. I found this in $:/core/macros/tag

  • Thats the thing about tiddlywiki, if you can see it already in tiddlywiki, its only a matter of looking for it.

class="tc-tag-label"

Snag_19fc66c5

1 Like

I was just asking for the pop up menu to look like the one of the tag button but without affecting the look of the button itself.

It is just how you layout the contents of the dropdown inside the reveal widget.

Title
<hr>
<$list ...
1 Like

The HTML structure for the tags popup menu is quite involved: each menu item is a div containing a span containing a link. But <$link> widgets don’t provide an actions attribute, so if you want to use the action widgets of my example you have to wrap all this inside an event catcher, maybe a <$linkcatcher> widget.
I’m not skilled enough to write this code, maybe someone else can help here?

Fred

1 Like

Fred, you can also uses buttons that can look like links to trigger actions on list items as well as navigate like a link.

Thanks Tones! I had tried with tag="div" to no avail, but with tag="a" I’ve got a working example for @Thomas_Chuffart :tada:
XabrinaExample2.json (4.1 KB)

There are still CSS issues with the pointer and I guess the original tag popup code is more elegant, but at least this example is a starting point…

Fred

1 Like

thank you @tw-FRed this example is more what I looked for.

I managed also to modify it using the .tc-btn-invisible class…

1 Like

@tw-FRed et al, perhaps I should have detailed;

  • There is arguably a simpler way which reduces the code complexity.
  • To make a link that allows actions to be assigned;
    • Rather than use alternative html tags you can just use the following class’s class="tc-btn-invisible tc-tiddlylink" as mentioned on the very last line of the ButtonWidget doco’
<$button to=<<currentTiddler>> class="tc-btn-invisible tc-tiddlylink">
Button name
</$button>
  • In this example it navigates to <<currentTiddler>> perhaps used inside a list.
    • But your actions could trigger new from template named in the <<currentTiddler>>
  • We are so used to using the link widget, or [[tiddlername]] or tiddlername with a link catcher, that we sometimes forget most links are in many ways just buttons. Then we get all the advantages of the button widget.
  • @Xabrina I believe you are content with the solutions you now have?
  • I have made a generic select-to-navigate macro and working on a generic select to action, where you could supply an action to create a tiddler using the selected template
  • However as is common for me I am going down a perfectionist rabbit hole trying to apply every trick in the book to make a very adaptable solution however that takes more time. eg
    • Provide any filter to generate the list
    • Configure title, label and tooltip
    • A display-filter to choose when to display the button at all
    • Use alternate classes as discussed
    • A set of actions to set fields or trigger new tiddler actions etc…
  • I will publish separately once I have something, unless asked here and particularly if asked by @Xabrina

Keep in mind I am always doing this kind of thing for myself so adding features to tiddlywiki’s are quick and easy, I have developed tiddlywiki into what I call a “Rapid software development environment”, yes it is possible :nerd_face:

2 Likes

Hello @TW_Tones.

Of course I’m happy!!! Instead of one solution I have two. :star_struck:

Just yesterday I was trying to use the code that @tw-FRed gave me along with what I already had previously to create tiddlers from pre-defined templates, and in the end I got everything working correctly.
With the last modification proposed by @Thomas_Chuffart and again made by @tw-FRed it even fits me much better.

Please, when you have something that you think is ready to share with us I would be happy to try it and see how it works. :nerd_face:

Thank you very much to everyone who has helped me directly or indirectly with this problem, this is the best thing this community has.

Thanks again and have a good day.

1 Like

Hello again.

I have found an effect when executing the button that I am not sure if it is normal or if I am doing something wrong. If I have two buttons, each in an open tiddler, if I activate one the other is activated.

I’m attaching a screenshot to give you a better idea.

Can this be avoided?

All the best.!

Yes :slightly_smiling_face:
The trick is to use the qualify macro to get a unique state tiddler name for each tiddler using the button.
Here is the code: XabrinaExample3.json (5.1 KB).
I included a clone of the example tiddler, for convenience.
You can look for the 3 lines of code containing myState in both example tiddlers.

Fred

1 Like

Hello @tw-FRed.

Now it works completely fine for me with your instructions. :partying_face:

Thank you very much again.

You can also add another parameter such as n to add into the qualification so you can have the same button more than once in the same tiddler, if that is needed.

  • I have done it in the general solution for popups I am developing. It will be available soon, after I resolve a regression, ie I fixed something but the problem came back.

eg <$set name=popup-state value={{{ [<qualify $:/temp/popup>addsuffix<n>] }}}> then use <<popup-state>> where n is a parameter in the procedure/macro.

1 Like

I am filing this under “Things I had no idea I needed until now”. This is awesome. Thanks tw-FRed!