TW5 home button?

341 views
Skip to first unread message

David Gifford

unread,
Nov 3, 2013, 4:23:58 PM11/3/13
to tiddl...@googlegroups.com
Any way to do a home button for TW5? That is, when you click on the SiteTitle, all the tiddlers close and the default tiddler opens?

There was just a thread on this for classic. Possible already in 5?

Dave

Stephan Hradek

unread,
Nov 3, 2013, 5:22:08 PM11/3/13
to tiddl...@googlegroups.com
I think it shouldn't be too difficult. As far as I can see, the code is already in startup.js.

Maybe Jeremy can make it a seperate function?

The code I think which should do it is in lines 37 to 50:

        // Get the default tiddlers
       var defaultTiddlersTitle = "$:/DefaultTiddlers",
               defaultTiddlersTiddler = $tw.wiki.getTiddler(defaultTiddlersTitle),
               defaultTiddlers = [];
       if(defaultTiddlersTiddler) {
               defaultTiddlers = $tw.wiki.filterTiddlers(defaultTiddlersTiddler.fields.text);
       }
       // Initialise the story and history
       var storyTitle = "$:/StoryList",
               story = [];
       for(var t=0; t<defaultTiddlers.length; t++) {
               story[t] = defaultTiddlers[t];
       }
       $tw.wiki.addTiddler({title: storyTitle, text: "", list: story},$tw.wiki.getModificationFields());

So if one can put that into a tiddler and can execute it (it's beyond my knowledge at the moment), it should be done.

Stephan Hradek

unread,
Nov 3, 2013, 6:37:45 PM11/3/13
to tiddl...@googlegroups.com
Tested it.

[[Homebutton]]
<html><button onclick="

var defaultTiddlersTitle = '$:/DefaultTiddlers',
    defaultTiddlersTiddler = $tw.wiki.getTiddler(defaultTiddlersTitle),
    defaultTiddlers = [];
if(defaultTiddlersTiddler) {
    defaultTiddlers = $tw.wiki.filterTiddlers(defaultTiddlersTiddler.fields.text);
}
var storyTitle = '$:/StoryList',
    story = [];
for(var t=0; t
<defaultTiddlers.length; t++) {
   
story[t] = defaultTiddlers[t];

}
$
tw.wiki.addTiddler({title: storyTitle, text: '', list: story},$tw.wiki.getModificationFields());
return false;
">Home</button></html>

And it seems to work.

Include {{Homebutton}} whereever you want one.

David Gifford

unread,
Nov 3, 2013, 6:44:27 PM11/3/13
to tiddl...@googlegroups.com
Cool! Works well. Just curious how to restyle it.


--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/nsECiXqk7fw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/groups/opt_out.



--
David Gifford
Christian Reformed World Missions, Mexico City

Jeremy Ruston

unread,
Nov 4, 2013, 4:33:05 AM11/4/13
to TiddlyWiki
In TiddlyWiki5 you don't need the <html> tag; you can just intermix HTML tags with wikitext.

I plan to add a message "tw-home" that does this; you'll be able to invoke it with <$button message="tw-home">Home</$button>.

Best wishes

Jeremy








--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/groups/opt_out.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Stephan Hradek

unread,
Nov 4, 2013, 8:54:03 AM11/4/13
to tiddl...@googlegroups.com, jeremy...@gmail.com


Am Montag, 4. November 2013 10:33:05 UTC+1 schrieb Jeremy Ruston:
In TiddlyWiki5 you don't need the <html> tag; you can just intermix HTML tags with wikitext.

I plan to add a message "tw-home" that does this; you'll be able to invoke it with <$button message="tw-home">Home</$button>.

While you are at it, why not allow <$button message="tw-home" set="A tiddler title">My Other Home</$button> where "A tiddler title" would be a tiddler, like $:/DefaultTiddlers is but for other "Stories". And why not also <$button message="tw-home" setTo="[[one tiddler title]] [[another tiddlertitle]]">My Third Home</$button>

Ton Gerner

unread,
Nov 4, 2013, 11:40:00 AM11/4/13
to tiddl...@googlegroups.com
Hi Dave,

Good you asked for a Home button; it is one of my favourites as well but I didn't know how to do it.
@Stephan: Thanks for the code.

The thing I learned is how to style it. I updated my guide for a toolbar in a top menu with a Home button; look there for the details [1], [2] or [3].
In short:
1) To replace the Home button with an icon, you need to replace 'Home' in Stephan's code (at the bottom) by transcluding an icon.
2) You need to add the class 'btn-invisible' to Stephan's button definition (at the top) to remove the button shape.

Cheers,

Ton

[1] https://dl.dropboxusercontent.com/u/2638511/TW5_test.htm
[2] http://five.tiddlywiki.com/ (Community)
[3] http://www.giffmex.org/tw5mall.htm (Page layout)

Jakob Schwichtenberg

unread,
May 17, 2020, 4:04:00 AM5/17/20
to TiddlyWiki
Where do I need to add this code

<html><button onclick="

var defaultTiddlersTitle = '$:/DefaultTiddlers',
    defaultTiddlersTiddler = $tw.wiki.getTiddler(
defaultTiddlersTitle),
    defaultTiddlers = [];
if(defaultTiddlersTiddler) {
    defaultTiddlers = $tw.wiki.filterTiddlers(
defaultTiddlersTiddler.fields.text);
}
var storyTitle = '$:/StoryList',
    story = [];
for(var t=0; t
<defaultTiddlers.length; t++) {
   
story[t] = defaultTiddlers[t];

}
$
tw.wiki.addTiddler({title: storyTitle, text: '', list: story},$tw.wiki.getModificationFields());
return false;
">Home</button></html>

to make the home button work? Simply putting it into a tiddler yields a button that does nothing.

Birthe C

unread,
May 17, 2020, 4:41:49 AM5/17/20
to TiddlyWiki
Jakob,

In the sidebar the tools tab you can find a home button. Check to show. Clicking the button will open your default tiddlers.


Birthe

Mat

unread,
May 17, 2020, 5:54:57 AM5/17/20
to TiddlyWiki
Jakob that code doesn't work because it is javascript which is disabled in TW.

Instead, you'd use a ButtonWidget and ActionNavigateWidget like described here.
Instead of hard coding titles there could be a ListWidget inside the button widget if you want.
And I'm not sure if you want to close all active tiddlers before 'going home' but this could also be done in the ButtonWidget.

<:-)

PMario

unread,
May 17, 2020, 5:55:07 AM5/17/20
to TiddlyWiki
hi,

Because of security reasons TW doesn't allow to execute js code like thils. htm code will be sanitized, 

-m

David Gifford

unread,
May 17, 2020, 8:35:41 AM5/17/20
to tiddl...@googlegroups.com
Ho Jakob,

I don't know where you got that home button, but it has tw- prefixes, which years ago were changed to tc- prefixes. So it is probably just a really old button.

Try inserting {{$:/core/ui/Buttons/home}}




--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/nsECiXqk7fw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.

Birthe C

unread,
May 17, 2020, 9:33:45 AM5/17/20
to TiddlyWiki
Reply all
Reply to author
Forward
0 new messages