Basic question about tiddler title

145 views
Skip to first unread message

Faber

unread,
Jun 4, 2020, 2:35:01 PM6/4/20
to TiddlyWiki
I'm searching for a smart way to obtain multiple link ready to click, based on tiddler current title, like this example:


Best with snippet and button to insert all strings in a snippet with a single click.

All of this doesn't work :

https://www.google.com/search?q={{!!title}}+other+term
[ext[https://www.google.com/search?q=<$field {!!title}+folkdancefootnotes]]
<$link to="https://www.google.com?q=<<currentTiddler>>"><$view field="title"/></$link>

\define mysearch()
https://www.google.com?q=<<currentTiddler>>+other+term
\end

How to do this?
Thanks.

Eric Shulman

unread,
Jun 4, 2020, 4:17:55 PM6/4/20
to TiddlyWiki
On Thursday, June 4, 2020 at 11:35:01 AM UTC-7, Faber wrote:
I'm searching for a smart way to obtain multiple link ready to click, based on tiddler current title, like this example:

This might help get you in the right direction:
\define google(term)
<a href={{{ [[https://www.google.com?q=$(currentTiddler)$+$term$]split[ ]join[+]] }}} target="_blank">$term$</a>
\end

How it works:
* To create the "href" value of the link, an "inline filter" is used to combine bits of static text with TW macro replacement syntax.
* Within a macro, the $(...)$ syntax is replaced by the value of the *variable* referenced between the parentheses.
* The variable has to be defined OUTSIDE the macro, in the calling context.  Fortunately, the "currentTiddler" variable is automatically defined by the TWCore and is always set to the title of the tiddler in which the macro output is being rendered.
* Within a macro, the $...$ syntax is replaced by the value of the *macro parameter* referenced between the dollar signs.
* The parameter is passed as quoted text when the macro is called.
* Note that a link to a google search term requires that all spaces have to be replaced with "+" characters.

To use it:
* Place the above code into a tiddler, and tag that tiddler with "$:/tags/Macro".  This will make the macro "global" so it can be used in other tiddlers.
* Then, in any tiddler (e.g., "Some Tiddler"), write something like this:
<<google "find this text">>
* The macro output will be an HTML link like this:
<a href="https://www.google.com?q=Some+Tiddler+find+this+text" target="_blank">find this text</a>

Let me know how it goes...

enjoy,
-e

Eric Shulman

unread,
Jun 4, 2020, 8:00:56 PM6/4/20
to TiddlyWiki
On Thursday, June 4, 2020 at 1:17:55 PM UTC-7, Eric Shulman wrote:
This might help get you in the right direction:
\define google(term)
<a href={{{ [[https://www.google.com?q=$(currentTiddler)$+$term$]split[ ]join[+]] }}} target="_blank">$term$</a>
\end 
 
Here's another version that doesn't need to define a macro and also provides an input field for the search term:
<$edit-text tiddler="$:/temp/google" tag="input" placeholder="enter search text" default="" />
<$button message="tm-open-external-window" param={{{ [[https://www.google.com?q=]] +[addsuffix<currentTiddler>] +[addsuffix[+]] +[addsuffix{$:/temp/google}] +[split[ ]join[+]] }}}>
   search
</$button>

1) Define a tiddler (e.g., "Google") containing the above code
2) Create any other tiddler containing the following:
{{||Google}}

How it works:
* As with the previous macro version, the desired URL is constructed using the currentTiddler value
* Instead of using a macro parameter to insert the search term, and $edit-text widget is used to save the term input into a temporary tiddler, $:/temp/google
* The contents of $:/temp/google are appended to the constructed URL
* A $button widget is used to open a new 'external' browser window with the fully constructed URL

To use it:
* Instead of invoking a macro (i.e., <<google ...>>), transclusion is used (i.e., {{||Google}} to display the input field and button
* Note the use of || in the transclusion.  This allows the *context* of the containing tiddler to be applied, which means that the value of currentTiddler is the title of the tiddler in which the transclusion occurs, rather than the title of the tiddler in which the input field and button are defined.

Again, let me know how it goes...

enjoy,
-e


TonyM

unread,
Jun 4, 2020, 8:15:34 PM6/4/20
to TiddlyWiki
Eric,

Once again inspired by you work, I recall that on https://www.w3schools.com/ a search is "enhanced by Google" and the results appear in a drop down.

I wonder if we could develop this for tiddlywiki?


Regards
Tony

Eric Shulman

unread,
Jun 4, 2020, 9:18:57 PM6/4/20
to tiddl...@googlegroups.com
On Thursday, June 4, 2020 at 5:15:34 PM UTC-7, TonyM wrote:
Once again inspired by you work, I recall that on https://www.w3schools.com/ a search is "enhanced by Google" and the results appear in a drop down.
I wonder if we could develop this for tiddlywiki?

Here's yet another version.  This one skips the Google search input page, and goes directly to the search results.
<$edit-text tiddler="$:/temp/google" tag="input" placeholder="enter search text" default="" />
<$vars keywords={{{ [<currentTiddler>] +[addsuffix[+]] +[addsuffix{$:/temp/google}] +[split[ ]join[+]] }}}>
<$vars      URL={{{ [[https://www.google.com/search?q=]] +[addsuffix<keywords>] }}}>
<$button message="tm-open-external-window" param=<<URL>>> {{$:/core/images/advanced-search-button}} </$button>
</$vars>
</$vars>

Note that this version uses $vars widgets to construct the desired search keywords and the URL before opening the external window.

This was not, strictly speaking, *necessary*, but was done to make the code more readable.

enjoy,
-e

TonyM

unread,
Jun 4, 2020, 10:41:02 PM6/4/20
to TiddlyWiki
Eric,

Nice.

I have tried to encourage myself to review tiddlers and record keywords relating to the subject in a keywords field.

I modified your keywords variable as follows
keywords={{{ [<currentTiddler>] [{!!keywords}] +[addsuffix[+]] +[addsuffix{$:/temp/google}] +[split[ ]join[+]] }}}

To include those keywords as well.

Its a great way to then reach out to the internet to research what the title and keywords describe

Also the edit field provided can be used to restrict the search as well eg
-google-adds

Great stuff

Thanks
Tony

Eric Shulman

unread,
Jun 4, 2020, 11:13:13 PM6/4/20
to tiddl...@googlegroups.com
On Thursday, June 4, 2020 at 7:41:02 PM UTC-7, TonyM wrote:
I have tried to encourage myself to review tiddlers and record keywords relating to the subject in a keywords field.
I modified your keywords variable as follows
keywords={{{ [<currentTiddler>] [{!!keywords}] +[addsuffix[+]] +[addsuffix{$:/temp/google}] +[split[ ]join[+]] }}}
To include those keywords as well.

Your modified keywords adds the $:/temp/google input contents twice!

For example, if the keywords field contains "foo bar" and the $:/temp/google input field contents is "test this", then the result of the inline filter is:
New+Tiddler+test+this+foo+bar+test+this

This is because
+[addsuffix{$:/temp/google}]
is applied to both the "[<currentTiddler>]" and "[{!!keywords}]" filter runs

The correct keywords filter syntax should actually be this:
keywords={{{ [<currentTiddler>] [{!!keywords}] [{$:/temp/google}] +[split[ ]join[+]] }}}

which lists all three sources of search terms (current tiddler, keywords field, and input field), splits them at any embedded spaces, and then joins the whole list with "+" signs to produce this result:
New+Tiddler+foo+bar+test+this

The new code is thus:
<$edit-text tiddler="$:/temp/google" tag="input" placeholder="enter search text" default="" />
<$vars keywords={{{ [<currentTiddler>] [{!!keywords}] [{$:/temp/google}] +[split[ ]join[+]] }}}>

<$vars      URL={{{ [[https://www.google.com/search?q=]] +[addsuffix
<keywords>] }}}>
<$button message="tm-open-external-window" param=<
<URL>>> {{$:/core/images/advanced-search-button}} </$button>
</$vars>
</$vars>

enjoy,
-e

TonyM

unread,
Jun 4, 2020, 11:31:57 PM6/4/20
to TiddlyWiki
Eric,

Thanks for that. I also made the mistake of using keywords that were already in the title.

Tony

Faber

unread,
Jun 5, 2020, 7:36:56 AM6/5/20
to TiddlyWiki
Work like a charm, thank you! This saves time for me. Tiddlywiki is a very good tool!
Reply all
Reply to author
Forward
0 new messages