Basic Problem -- How to get Tiddler text into a variable (NOT a transclusion)

152 views
Skip to first unread message

@TiddlyTweeter

unread,
Jun 3, 2018, 10:28:28 AM6/3/18
to TiddlyWiki
I need to get the literal text of a Tiddler into a simple macro/variable. I have studied the documentation (like https://tiddlywiki.com/#Concatenating%20text%20and%20variables%20using%20macro%20substitution) but still can't see how to do it ...

Use Case

tiddler title: "$:/PerryMason"
text content: "Paul Drake"

All I want to do is get the literal plain text "Paul Drake" in to a variable \defined perry().

Anyone know an easy way to do that?

Help much appreciated
Josiah

Diego Mesa

unread,
Jun 3, 2018, 10:52:56 AM6/3/18
to TiddlyWiki
Hello Josiah,

On Tiddlywki.com if you type:

<$set name="perry" tiddler="HelloThere" field="text">
hello! <<perry>>
</$set>

You get the literal text of the tiddler HelloThere. Is this what you mean?

@TiddlyTweeter

unread,
Jun 3, 2018, 11:20:49 AM6/3/18
to TiddlyWiki
Ciao Diego

Looks part the way there. But I need get the (literal text) value "Paul Drake" into a Global Macro <<perry>> for use elsewhere. As far as I grasp $set use is limited to its context? Excuse my ignorance if I'm wrong.

J.

Mark S.

unread,
Jun 3, 2018, 11:57:33 AM6/3/18
to TiddlyWiki
I think you need to explain more about your use case.

You could just create a global macro:

\define perry() {{HelloThere!!text}}

and then use <<perry>> anywhere. But I suspect you're trying to do something with the text.

Good luck!
-- Mark

wjam

unread,
Jun 3, 2018, 11:59:34 AM6/3/18
to TiddlyWiki
you can use the wikify widget where

text='<$view tiddler="your tiddler" field="text"/>'

wjam

@TiddlyTweeter

unread,
Jun 3, 2018, 1:28:25 PM6/3/18
to tiddl...@googlegroups.com
Mark S. wrote:
I think you need to explain more about your use case.

You are right. The difficulty IS explaining it.

Transclusion is so sophisticated in TW many don't realise that when you create macro/variables you are transferring the "transclusion code" into it, not the value, most of the time.
 
 You could just create a global macro:

\define perry() {{HelloThere!!text}}


Works perfectly in most transclusion contexts. But you can see the issue with that is if you use the macro in a context like a command processor that only accepts literal text... the macro/variable isn't holding the value, but the transclusion code to display it.

path: 'C:\\bag\\PortableApps\\twMU\\pages\\tw\\tw_{{$:\\HelloThere!!text}}\\index.html'
 
I will try layout a more detailed example and be as clear as I can. But I think this starts to illustrate the issue I hope.

Thanks
Josiah

Mark S.

unread,
Jun 3, 2018, 1:39:21 PM6/3/18
to TiddlyWiki
I imagine this relates to invoking commands from Bob, which I haven't studied. Where is this "path: 'c:\\....'" structure located? Is it in a regular tiddler?

If it really needs to be hard-coded text, then I think you would need a button that would trigger actions that would create the actual text. It would be something you need to do whenever updating your configuration, I suppose.

-- Mark
I will try layout a more detailed example and be as clear as I can. But I think this starts to illustrates the issue I hope.

Thanks
Josiah

@TiddlyTweeter

unread,
Jun 3, 2018, 2:01:47 PM6/3/18
to TiddlyWiki
Yeah its to do with Bob automation.

It works perfectly if I give it a defined literal string like this ...

\define twName() Paul Drake
\define sfTo() ..\..\pages\tw\tw_$(twName)$\

And then click command to make a wiki ...

<$button>
  Make a ''<
<twName>>'' single file
  <$action-websocketmessage $type='buildHTMLWiki' outputFolder=<
<sfTo>> outputName="index.html" />
</$button>

Console report ... works fine ...

Build Wiki
Built Wiki:  C:\bag\PortableApps\twMU\pages\tw\tw_Paul Drake\index.html

My idea was NOT to have to hard code the name of every output wiki, but rather use the text field of "$:/WikiName" since that is built in. When Bob creates a wiki that Tiddler is created.

I never envisaged that getting the plain text into a global variable could be so complex! I thought the issue was just me :-). Apparently its a bit more complicated.

J.

@TiddlyTweeter

unread,
Jun 3, 2018, 2:22:23 PM6/3/18
to TiddlyWiki
Mark

Footnote ... the "c:\\ is" an apport of error checking in node/Bob. Its not actually the console achieving anything.

Internally I think node based systems use "\\" to "escape" in paths. When things run well you never see it.

J.

@TiddlyTweeter

unread,
Jun 3, 2018, 2:22:58 PM6/3/18
to TiddlyWiki
Ciao wjam

How would I get the output of that into a global macro/variable ?

Any tips appreciated
Josiah

Mark S.

unread,
Jun 3, 2018, 2:35:05 PM6/3/18
to TiddlyWiki
Where does this button appear? In a template, or a single launch tiddler?

More importantly, why not wrap a <$set name=twName value={{$:/PerryMason}}> </$set> around the button (deleting macro twName of course) ?

Good luck!
-- Mark

@TiddlyTweeter

unread,
Jun 3, 2018, 3:50:49 PM6/3/18
to TiddlyWiki
It is in a single tiddler with several other buttons that just vary slightly. Its a Tiddler from which I "Automate" the wiki using Bob commands.

Mark S.

unread,
Jun 3, 2018, 6:46:00 PM6/3/18
to TiddlyWiki
So does

\define sfTo() ..\..\pages\tw\tw_$(twName)$\


<$set name=twName value={{$:/PerryMason}}>
<$button>
  Make a ''<
<twName>>'' single file
  <$action-websocketmessage $type='buildHTMLWiki' outputFolder=<
<sfTo>> outputName="index.html" />
</$button>
</$set>

Not work?

-- Mark

TonyM

unread,
Jun 3, 2018, 7:28:43 PM6/3/18
to TiddlyWiki
Josiah,

I see no reference in this discussion to using the wikify widget rather than set to lock the text value into the wikify defined variable.

Perhaps that would help

Regards
Tony

BurningTreeC

unread,
Jun 4, 2018, 4:18:20 AM6/4/18
to TiddlyWiki
@TiddlyTweeter ,

That string where you want to transclude that tiddler text - is it in a BOB config file?


BurningTreeC

unread,
Jun 4, 2018, 4:26:51 AM6/4/18
to TiddlyWiki
\define get-wiki-path()
C:\\bag\\PortableApps\\twMU\\pages\\tw\\tw_$(wikiName)$\\index.html
\end
\define actions()
<$action-setfield $tiddler="ma-tiddla" $index="path" $value="""$(wikiPath)$"""/>
\end

<$vars wikiName={{tiddlerwithwikiname}}>
<$vars wikiPath=<<get-wiki-path>>>
<$button>
<<actions>>
set
</$button>
</$vars>
</$vars>

PMario

unread,
Jun 4, 2018, 4:37:26 AM6/4/18
to TiddlyWiki
Hi,
You only need 1 !!! vars widget. Have closer look at the docs.

-m

BurningTreeC

unread,
Jun 4, 2018, 4:51:10 AM6/4/18
to TiddlyWiki
Hi,
You only need 1 !!! vars widget. Have closer look at the docs.

Hi @pmario - that's apparently NOT true

from the docs: "The content of the <$vars> widget is the scope for the value assigned to the variable."

testing with one vars widget results in the wikiName variable not defined in get-wiki-path 

-m

BurningTreeC

unread,
Jun 4, 2018, 4:56:40 AM6/4/18
to TiddlyWiki
in simple german: I can set multiple variables with the vars widget, but if I need one of those variables in another one, I need another vars widget within the scope of the one that defines the variable I need for the second one.

@TiddlyTweeter

unread,
Jun 5, 2018, 5:48:44 AM6/5/18
to TiddlyWiki
Mark S.

That is good.

I delayed replying till I tested it with the buttons of automate (some quite complex) properly.

It works well without adding too much code.

Thankyou! J.

Mark S. wrote:
So does


Not work?

@TiddlyTweeter

unread,
Jun 5, 2018, 5:52:34 AM6/5/18
to TiddlyWiki
Ciao BTC

Very useful to see. Thanks!

I do see a more complex situation where I could need that and not just "set".

Best wishes, J
Reply all
Reply to author
Forward
0 new messages