On Sunday, June 7, 2020 at 5:48:31 AM UTC-7, Jake wrote:
>
> Wow! Looks like it worked! Thanks a lot, Eric!
> "BUT..." :)  what if I want to make it a bit more complex? What if I want 
> to make "MyFolder" also a variable?
> e.g. if I have folders like "MyDocs", "MyImages", "MyData", "Downloads", 
> etc. with this method, as I understood, I would have to make a separate 
> variable for each, like:
>
> MyGoto Macro:
> \define godocs(text,file) <$vars folder={{MyDocs Path}}><<link2file 
> "$text$" "$file$">></$vars>
> \define goimg(text,file) <$vars folder={{MyImages Path}}><<link2file 
> "$text$" "$file$">></$vars>
> \define godata(text,file) <$vars folder={{MyData Path}}><<link2file 
> "$text$" "$file$">></$vars>
> \define godownloads(text,file) <$vars folder={{Downloads Path}}><<link2file 
> "$text$" "$file$">></$vars>
> \define link2file(text,file) [ext[$text$|file:///$(folder)$/$file$]]
> with tiddlers [[MyDocs Path]], [[MyImages Path]], [[MyData Path]], 
> [[Downloads Path]] defining path to the folders.
> and the usage
> <<godocs "My awesome document" "Agreement/doc1.doc">>
> <<goimg "My Fabulous picture" "Scenery/lake.img">> etc. 
>

Yes.  That would work just like you have written.  The name of the macro 
implies the name of the tiddler containing the path text.
 

> but what if I want a "universal" macro with usage like:
> <<gofolder "text to show" "Folder" "MySubfolder/myfile.txt">>
>

That's even easier.  You can just add a third param to the outer <<link>> 
macro, and combine it with the inner <<link2file>> macro, like this:
\define gofolder(text,folder,file) [ext[$text$|file:///$folder$/$file$]]
and then use it as you have indicated:
<<gofolder "text to show" "Folder" "MySubfolder/myfile.txt">>

Notice how, since you are no longer getting the folder from the contents of 
a tiddler, there's no need for an
outer macro to use transclusion (the {{...}}) to get the variable value for 
use with an inner macro, and
$(folder)$ (a *variable* substitution) has been replaced by $folder$ (a 
*macro param* substitution).

However, since you would then be providing all the needed values as 
parameters to the macro call,
there's really no reason for the folder and file values to be passed as 
separate params, and you could just write:
\define gofolder(text,file) [ext[$text$|file:///$file$]]
which you would call like this:
<<gofolder "text to show" "Folder/MySubfolder/myfile.txt">>

See.  Nice and simple!

enjoy,
-e 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/8c87d7d4-57d6-47df-b8b2-f5a6fee8c2d6o%40googlegroups.com.

Reply via email to