nesting double curly brackets

431 views
Skip to first unread message

Dave

unread,
Feb 27, 2017, 1:34:34 AM2/27/17
to TiddlyWiki
I'm trying to use the value of a field to return another value from a dictionary tiddler

this would give the field value: {{Lumbar Kemps!!ips}}


and if I knew the answer was e.g."leg pain", I could get the value from the dictionary tiddler [[Lumbar Kemps Dxs]] like this:

{{Lumbar Kemps Dxs##leg pain}}


but I need to do it programmatically, and this doesn't work:

{{Lumbar Kemps Dxs##{{Lumbar Kemps!!ips}}}}


Is there a way to do this?


Thanks,
- Dave

Mat

unread,
Feb 27, 2017, 1:45:25 AM2/27/17
to TiddlyWiki
No complete answer;

The {{..}} is just a quick/convenient syntax for the <$transclude...> widget. You cannot nest the former but you can nest the latter.

I don't know if this will be enough to solve your need but it might be a step on the way or otherwise just good to know.

<:-)

Jed Carty

unread,
Feb 27, 2017, 5:47:11 AM2/27/17
to TiddlyWiki
You can do this using a helper macro. I have some things written about it here

Dave

unread,
Feb 27, 2017, 9:53:01 AM2/27/17
to TiddlyWiki
Thanks Jed, I'll take a look at that.

In the meantime, what's the code to transcode from a data tiddler?

I tried this to no avail:
<$transclude tiddler="my tiddler" data="my data">

I also tried "value"

I just couldn't find any reference to anything besides the curly bracket method

PMario

unread,
Feb 27, 2017, 11:38:10 AM2/27/17
to TiddlyWiki
On Monday, February 27, 2017 at 3:53:01 PM UTC+1, Dave wrote:
I tried this to no avail:

<$transclude tiddler="my tiddler" data="my data">


Hi Dave,
Have a look at the attribute names: index
 
http://tiddlywiki.com/#TranscludeWidget:TranscludeWidget%20DataTiddlers

-m

Dave

unread,
Feb 27, 2017, 5:47:14 PM2/27/17
to TiddlyWiki
aha! index is what i was looking for - thanks!

Dave

unread,
Feb 27, 2017, 11:48:31 PM2/27/17
to TiddlyWiki
Okay, I feel like I'm banging my head against the wall - why is this not working?

\define s.test.result()
 
<$transclude tiddler="TempTest" field="tempfield"/>
\end

\define s.test(testname,testfield)
<$set name="tests" value="testDictionary"><!-- the whole list of all tests -->
<$set name="subtest" value=$testfield$><!-- name of the field like "lopp" to put finding into-->
<$select tiddler="TempTest" field="tempfield"><!-- this selection puts findings into this tiddler and field-->
<$list filter="[<tests>getindex[$testname$]]"><!-- gets the list of options for this test-->
<$list filter=<<currentTiddler>>><!-- this and next line for breaking up list for selection(?)-->
<option value=<<currentTiddler>>><$text text=<<currentTiddler>>/></option>
</$list>
</
$list>
</$select>
tiddler="$testname$ Dxs" index="<$macrocall $name='s.test.result'/
>" <!-- A-->
<$transclude tiddler="
$testname$ Dxs" index="<$macrocall $name='s.test.result'/>"/><!--B-->
</$set>
</$set>

\end

<<s.test "
Lumbar Kemps" "ips">>


The select box thing works fine, but my problem is the difference between <!-- A--> and <!--B-->


the "A" part correctly prints this out:
tiddler="Lumbar Kemps Dxs" index="leg pain"

which is the guts of the transclusion I want to do, but part "B" does nothing, whereas outside of the macro, if I put that content in it, it would work correctly.

I thought maybe I'd have to have the main select option thing outside of a macro and just transclude that tiddler wherever I need it, but then how could I pass the parameters to it in that case?

Any ideas?






Jed Carty

unread,
Feb 28, 2017, 10:29:52 AM2/28/17
to TiddlyWiki
You need to use set widgets and $(Variable)$ syntax like in what I linked above, you can't use the macrocall widget in places like index=<$macrocall name=whatever..., you have to use a set widget and $(variable)$ inside that.

Dave

unread,
Feb 28, 2017, 1:54:21 PM2/28/17
to TiddlyWiki
Yeah I tried that and couldn't get it to work.  I came to the conclusion that a variable set in one macro couldn't be used in another macro.  The method in your example there had variables set outside of the macro (i.e. in the "normal tiddler area") and that seemed to transfer into the macro that used it, but I couldn't get it to set a variable in one macro and transfer it to another macro called from the first.  But maybe I'm doing it wrong.  Should that be possible?  Is there maybe another syntax to make a set variable global in scope?

Dave

unread,
Feb 28, 2017, 5:41:45 PM2/28/17
to tiddl...@googlegroups.com
Here's another attempt that doesn't work:

\define s.test.result()
<$transclude tiddler='$(mytestname)$' field='$(mytestfield)$'/>
<$set name="foo" value="<$transclude tiddler='$(mytestname)$' field='$(mytestfield)$'>"/>
foo
is <<foo>> or $foo$ or $(foo)$.
\end

\define s.test(testname,testfield)
<$set name="mytestname" value="$testname$">
<$set name="mytestfield" value="$testfield$">

<$set name="tests" value="testDictionary"><!-- the whole list of all tests -->
<$set name="subtest" value=$testfield$><!-- name of the field like "lopp" to put finding into-->
<$select tiddler="$testname$" field=<<subtest>>><!-- this selection puts findings into this tiddler and field-->

<$list filter="[<tests>getindex[$testname$]]"><!-- gets the list of options for this test-->
<$list filter=<<currentTiddler>>><!-- this and next line for breaking up list for selection(?)-->
<option value=<<currentTiddler>>><$text text=<<currentTiddler>>/></option>
</$list>
</
$list>
<
/$select>
:<<s.test.result>>:
</
$set>
</$set>
</
$set>
</$set>

\end


I call the first macro from the second, and variables from <<s.test>> to <<s.test.result>> are working because that first "<$transclude tiddler='$(mytestname)$' field='$(mytestfield)$'/>" works the way its supposed to. 

What I can't figure out is how to put that output into another variable.  I'm used to using bash where I could do something like Var=$(cat somefile.txt) that would put the output of the cat command into the variable for use elsewhere.

I.e. the line "
foo is <<foo>> or $foo$ or $(foo)$." doesn't do anything except "foo is or $foo$ or ."

Jed Carty

unread,
Mar 1, 2017, 6:30:24 AM3/1/17
to TiddlyWiki
You can not set a value in one widget with another widget, that is the whole problem here. Your line 

<$set name="foo" value="<$transclude tiddler='$(mytestname)$' field='$(mytestfield)$'>"/>

won't work. You can just use the {{ }} syntax like this:

<$set name='foo' value={{$(mytestname)$!!$(mytestfield)$}}/>

although that line does nothing because the variable foo is only defined inside the start and end tags of the set widget so I am not sure what is supposed to happen there.

For the full thing, try this:

\define s.test.result()
<$transclude tiddler='$(mytestname)$' field='$(mytestfield)$'/>
<$set name="foo" value={{$(mytestname)$!!$(mytestfield)$}}>

foo
is <<foo>> or $foo$ or $(foo)$.
</$set>

\end

\define s.test(testname,testfield)
<$set name="mytestname" value="$testname$">
<$set name="mytestfield" value="$testfield$">

<!--subtest isn't actually needed anywhere, just use $testfield$ -->
<!-- defining tests is also redundant because using the list operator takes care of that -->
<!-- use triple quotes around names like this to prevent trouble caused by names having " in them. -->
<$select tiddler="""$testname$""" field="""$testfield$"""><!-- this selection puts findings into this tiddler and field-->

<!-- Use the list operator so you only need one list widget here -->
<$list filter="[list[testDictionary##$testname$]]"><!-- gets the list of options for this test-->

<option value=<<currentTiddler>>><$text text=<<currentTiddler>>/
></option>
</$list>
</
$select>
:<<s.test.result>>:
</$set>
</
$set>

\end


Dave

unread,
Mar 1, 2017, 11:02:17 AM3/1/17
to TiddlyWiki
Thank you so much for explaining these concepts to me Jed (and Mat and PMario).  I can tell intuitively that TW5 is the tool I need for what I want to do, but sometimes the details of how everything relates (macros and widgets and filter lists) is a little mindboggling sometimes (I'm not a programmer by profession)

I'll play with this for a while and post how it goes either way :)

Dave

unread,
Mar 1, 2017, 11:06:17 PM3/1/17
to TiddlyWiki
Okay, thank you all for your help.

The final piece was put in place by Mark S. here:
https://groups.google.com/forum/#!topic/tiddlywiki/g1qp3_Ln-J4

and here's the final thing that works

\define s.test.result(mytestname,myresult)
<$transclude tiddler="$mytestname$ Dxs" index="$myresult$"/>
\end

\define s.test(testname,testfield)

<$select tiddler="""$testname$""" field="""$testfield$""">
<$list filter="[list[testDictionary##$testname$]]"><!-- gets the list of options for this test-->
<option value=<<currentTiddler>>><$text text=<<currentTiddler>>/></option>
</$list>
</
$select>
<$set name="result" value={{$testname$!!$testfield$}}>
<$macrocall $name=s.test.result myresult=<<result>> mytestname="$testname$" />
</$set>
\end

<<s.test "Lumbar Kemps" "lopp">>




Reply all
Reply to author
Forward
0 new messages