[TW5] How can I "generate" a tiddler-link

319 views
Skip to first unread message

Stephan Hradek

unread,
Dec 2, 2013, 7:52:21 AM12/2/13
to tiddl...@googlegroups.com
I tried

Tiddler Title: linktest
Tiddler content:

\define join3(l, m, r)
$l$$m$$r$
\end
\define new_link()
<$link to=<<join3 "Comment for '" {{!!title}} "'">>><<join3 "Comment for '" {{!!title}} "'">></$link>
\end

<<new_link>>

But what I get is the text

Comment for 'linktest'

but the link itself goest to

Comment for '{{!!title}}'

So why is {{!!title}} not resolved there?

Or how could I get a correct link?

Stephan Hradek

unread,
Dec 2, 2013, 11:30:54 AM12/2/13
to tiddl...@googlegroups.com
So I found one way which seems to work - but I don't see the logic in it.

\define the_link()
[[Comment for '$(x)$']]
\end

\define okay_link()
<$set name="x" value={{!!title}}>
<<the_link>>
</$set>
\end

<<okay_link>>

A similar way, but one level less does not work:

\define nok_link()
<$set name="x" value={{!!title}}>
[[Comment for '$(x)$']]
</$set>
\end

<<nok_link>>

To be honest: I find this quite confusing (and frustrating).

What's most confusing: We have several ways of accessing similar stuff.

At least we have:

$parameter$ - for macro parameters
$
(variable)$ - for variables

It seems to me as if these variables are a kind of a global for macros but do not work outside of macros.

<$set name="variable" value="val">
here we can't use $(variable)$
while <
<macro>> will be able to use it
</$set>






Jeremy Ruston

unread,
Dec 2, 2013, 12:16:32 PM12/2/13
to TiddlyWiki
On Mon, Dec 2, 2013 at 4:30 PM, Stephan Hradek <stephan...@gmail.com> wrote:
So I found one way which seems to work - but I don't see the logic in it.

\define the_link()
[[Comment for '$(x)$']]
\end

\define okay_link()
<$set name="x" value={{!!title}}>
<<the_link>>
</$set>
\end

<<okay_link>>

A similar way, but one level less does not work:

\define nok_link()
<$set name="x" value={{!!title}}>
[[Comment for '$(x)$']]
</$set>
\end

<<nok_link>>

The reason that the second example doesn't work is because the variable 'x' doesn't exist at the time that the macro parameters and variables are being substituted. The nested macros are a way around that.
To be honest: I find this quite confusing (and frustrating).

What's most confusing: We have several ways of accessing similar stuff.

At least we have:

$parameter$ - for macro parameters
$
(variable)$ - for variables

It seems to me as if these variables are a kind of a global for macros but do not work outside of macros.

<$set name="variable" value="val">
here we can't use $(variable)$
while <
<macro>> will be able to use it
</$set>


Variables and macros are actually the same thing.

Variables do work outside of macros (via the <<variable>> syntax, or <$macrocall> widget), but there's no text substitution outside of macros, which is why the $(variable)$ syntax doesn't work outside of macros.

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

Martian

unread,
Apr 15, 2016, 9:18:19 AM4/15/16
to TiddlyWiki, jeremy...@gmail.com
Hello!

2 macros combo - is it still an only way to generate a link in TW5 ?

I am trying just to generate link as [[LinkText|some text+{{!!code}}]]
and nothing of following doesn't work 

\define getfoo(title=<<current>>)
{{foo1!!code}}
\end


test
<<getfoo>>


[[{{foo1!!code}}]]


[[<<getfoo>>]]


<$link to=<<getfoo>> >Link Text</$link>


<$link to={{foo1!!code}}>Link Text</
$link>


<$link to=<$transclude field="code/> >Link Text</$link>



понедельник, 2 декабря 2013 г., 20:16:32 UTC+3 пользователь Jeremy Ruston написал:

Martian

unread,
Apr 15, 2016, 9:49:46 AM4/15/16
to TiddlyWiki
Well,
it seems that no need in 2 level of macros and variable set. 
Instead <$macrocall> should be used

\define the_link(x)
[[Comment for '$x$']]
\end

<$macrocall $name="the_link" x={{!!title}}/>


понедельник, 2 декабря 2013 г., 19:30:54 UTC+3 пользователь Stephan Hradek написал:

Eric Shulman

unread,
Apr 15, 2016, 9:57:49 AM4/15/16
to TiddlyWiki, jeremy...@gmail.com
On Friday, April 15, 2016 at 6:18:19 AM UTC-7, Martian wrote:
Hello!
I am trying just to generate link as [[LinkText|some text+{{!!code}}]]
and nothing of following doesn't work 

Try this:
\define makelink(text,prefix,link)
[[$text$|$prefix$$link$]]
\end

<$macrocall $name="makelink" text="LinkText" prefix="prefix" link={{!!code}} />

Some feedback on your attempts:

\define getfoo(title=<<current>>)
{{foo1!!code}}
\end

* <<current>> is not a pre-defined variable, so it has no assigned value.  The TWCore sets <<currentTiddler>> to title of the current tiddler.  Perhaps that is the variable you were thinking of
* The syntax for defaults for macro params is paramname:value (not paramname=value) and only accepts literal values surrounded by delimiters using single-quotes ('foo'), double-quotes ("foo"), doubled square brackets ([[foo]]), or tripled double quotes ("""foo""").  You can't use a reference to another variable (or a transcluded field value).
* You declare the 'title' param, but never *use* it in the macro definition, so it's not clear what you intend to use it for.

test <<getfoo>>

* invoking <<getfoo>> here returns "{{foo1!!code}}", which is then rendered as a transclusion, displaying the value in the specified field

[[{{foo1!!code}}]]
[[<<getfoo>>]]

* you can't use transclusion or variable/macro invocation *within* the link syntax.
 
<$link to=<<getfoo>> >Link Text</$link>

* the macro returns "{{foo1!!code}}" and is not recursively re-parsed to retrieve the value contained in that field.  Thus, you are linking to a tiddler whose title is literally "{{foo1!!code}}".. which, is very likely NOT what you intended.

<$link to={{foo1!!code}}>Link Text</$link>

* This will work... but only links a tiddler whose title is the value in the field, without adding your desired title prefix (e.g., "sometext-" 

<$link to=<$transclude field="code/> >Link Text</$link>


*  You cannot invoke a widget to assign a value to a macro param.  Widgets generate/render output.  They do not return values. 

Hope this helps,

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

Martian

unread,
Apr 15, 2016, 10:24:33 AM4/15/16
to TiddlyWiki, jeremy...@gmail.com
Eric, thank you a lot for you comments!
Now it become much more clear. 
<$macrocall...> looks good for me.

пятница, 15 апреля 2016 г., 16:57:49 UTC+3 пользователь Eric Shulman написал:
Reply all
Reply to author
Forward
0 new messages