Transclusion within a string

1,013 views
Skip to first unread message

Mike

unread,
Feb 3, 2014, 8:40:25 AM2/3/14
to tiddl...@googlegroups.com
I'd like to have a field, e.g. "email", and then use that field in a string:

<a href="mailto:<$view field="email">">click to email</a>

But the resulting link just goes to "mailto:<$view field="email">"". Any ideas? I've also tried with the {{!!email}} notation, but it does the same thing as soon as it's inside quotes. I don't really want to use a macro, which seems much more heavy-weight than necessary. I also tried using

<$view field="email" template="mailto:$value$">

but (and maybe this is because I'm using 5.07beta) it seemed to completely ignore the template parameter.

Even if that last method could work it's syntactically heavy, so I'm hoping there's some quirk or escape sequence to let me use {{}} right inside the quoted string.

Thanks!

Stephan Hradek

unread,
Feb 3, 2014, 8:56:34 AM2/3/14
to tiddl...@googlegroups.com
Does this help?

\define mailto(email link)
<a href="mailto:$email$">$link$</a>
\end

<$macrocall $name="mailto" email={{!!email}} link="mail me"/
>


Mike

unread,
Feb 3, 2014, 9:26:15 AM2/3/14
to tiddl...@googlegroups.com
That sort of works, but ...

1) I'd have to include / define that macro in every tiddler where i wanted to use it, right? Is there an easy way to put all my macros in one tiddler and then just include that into other tiddlers?

2) This seems like an incredibly long way to go around for what amounts to string concatenation. Suppose I want to generate a URL with a field value in the middle of it (versus at the end of it). I could attempt something like the following (sorry, I'm not sure how to post code blocks):

\define cc(a:"",b:"")
$a$$b$
\end

<a href=<<cc <<cc "http://google.com/#q=" "xyz">> {{!!x}}>> >link</a>

Where cc is for CONCATENATE, but even that doesn't work because it doesn't properly process the nested macros. I guess using the full macrocall widget might work, but it's so long! Is there not a good way to just do substring insertion in general?

The <$view> widget claims it supports templates, but I couldn't get it to work.

Mike

unread,
Feb 3, 2014, 9:50:21 AM2/3/14
to tiddl...@googlegroups.com
Aaaah, this is maddening. It's so close. Suppose I create a tiddler with the fields:
x = mike
email = {{!!x}}

then, amazingly,
{{!!email}} displays "mike"
and, weirdly,
<a href={{!!emai}}>link</a> creates a link to "{{!!x}}". hmm.

even weirder, changing the email field to be
email = mailto:{{!!x}}

then
{{!!email}} displays "mailto:{{!!x}}"
and, weirdly,
<a href={{!!email}}>link</a> creates a link to "mailto:{{!!x}}".

There is some crazy stuff going on between the TW parser and the rendering engine that I'm not following.

Stephan Hradek

unread,
Feb 3, 2014, 10:52:02 AM2/3/14
to tiddl...@googlegroups.com


Am Montag, 3. Februar 2014 15:26:15 UTC+1 schrieb Mike:
That sort of works, but ...

1) I'd have to include / define that macro in every tiddler where i wanted to use it, right?

Right
 
Is there an easy way to put all my macros in one tiddler and then just include that into other tiddlers?

No

But you might want to create a javascript macro from it? Check http://tw5magick.tiddlyspot.com I show there the a simple example which might be sufficienent for you. I also have there a bookmarklet which can translate a normal TW5 macro to JavaScript.


2) This seems like an incredibly long way to go around for what amounts to string concatenation


I agree

Stephan Hradek

unread,
Feb 3, 2014, 1:09:26 PM2/3/14
to tiddl...@googlegroups.com


Am Montag, 3. Februar 2014 15:26:15 UTC+1 schrieb Mike:
That sort of works, but ...

Another idea (Can be seen on http://skeeve.tiddlyspot.com check "Mike's mail" and "mailto")

tiddler: Mike's Mail
email: mi...@do.main
text: {{!!title||mailto}}

tiddler: mailto
text
:

\define mailto(email)
<a href="mailto:$email$">click to email</a>
\end

<$macrocall $name="mailto" email={{!!email}}/
>


Julie

unread,
Feb 3, 2014, 3:17:59 PM2/3/14
to tiddl...@googlegroups.com
Le lundi 3 février 2014 15:26:15 UTC+1, Mike a écrit :
The <$view> widget claims it supports templates, but I couldn't get it to work.

 Not really... the ViewWidget claims that it supports templates with certain formats, and in the formats list only the date format seems to work with a template.

Jeremy Ruston

unread,
Feb 3, 2014, 3:41:02 PM2/3/14
to TiddlyWiki
Hi Mike

Going back to your original question, consider the example you gave:

<a href="mailto:<$view field="email">">click to email</a>

At the moment, that doesn't work because the double quotes on the href attribute cause the value to be interpreted as a literal string. The docs point out that we also support quoting attribute values with double curly braces (for transclusion) and double angle brackets (for macro invocations).

We could also support a quote symbol that caused the attribute value to be parsed as wikitext and rendered. For example, using quadruple round brackets for illustration:

<a href=((((mailto:<$view field="email">))))>click to email</a>

The reason originally that I didn't support something like that format is because it felt like it led to overly complex symbol soup (which is a frequent danger for TW5). I felt that the macro syntax offered a way to simplify things by allowing the gobbledegook needed for the attribute value to be packed up into a neat named macro definition.

Anyhow, supporting element attributes in wikitext remains an option.

Also, it's worth mentioning that TW5 will support global macros soon.

Aaaah, this is maddening. It's so close.

I'll try to work through the examples, but appreciate your feedback.
 
Suppose I create a tiddler with the fields:
x = mike
email = {{!!x}}
then, amazingly, 
{{!!email}} displays "mike"

Transclusion wikifies the transcluded tiddler field value.
 
and, weirdly,
<a href={{!!emai}}>link</a> creates a link to "{{!!x}}". hmm.

Transcluding an element attribute value currently does not wikify the transcluded tiddler field value.
 
even weirder, changing the email field to be
email = mailto:{{!!x}}
then 
{{!!email}} displays "mailto:{{!!x}}"
and, weirdly,
<a href={{!!email}}>link</a> creates a link to "mailto:{{!!x}}".

Subtly, what's going on here is that TW5 is wikifying the text "mailto:{{!!x}}", and it sees the "mailto:" part as the start of a mailto URI. It treats the text up to the closing curly braces as part of the literal mailto URI, and so never sees the transclusion.
 
There is some crazy stuff going on between the TW parser and the rendering engine that I'm not following.

Hopefully that clarifies the present situation a little.

I think we need to add ways to explicitly specify whether the target text of a transclusion or macro invocation is to be wikified or not. There are situations where both are required.

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

Mike

unread,
Feb 3, 2014, 6:44:44 PM2/3/14
to tiddl...@googlegroups.com, jeremy...@gmail.com
Yeah, functionality like you describe, with the quadruple round bracket, would be good for having the flexibility when needed.

I thought about it and I wonder if there's a way to just have the parser combine (string literal concatenation) sibling nodes of the parse tree when they're both string literals. That way both the string literal and the wikified transclusion would be mashed together. That way it could be:

<a href="http://google.com/#q="{{!!x}}>link</a>
becomes
<a href="http://google.com/#q=""value of field x">link</a>
becomes
<a href="http://google.com/#q=value of field x">link</a>

As an alternative, would it be possible to add a layer of recursion so that any block which gets wikified is reparsed (and rewikified) until it doesn't change? That would probably create lots of side issues, but it would allow nesting of widgets, etc.

Thanks for your excellent response. I apologize if the questions or suggestions I have show my ignorance of how TW works under the hood.

-Mike

Mike

unread,
Feb 3, 2014, 10:10:05 PM2/3/14
to tiddl...@googlegroups.com, jeremy...@gmail.com
I was thinking more about it and tried something but I couldn't get it to work. I tried to update the <$fields> widget to have an extra parameter $fieldList and change "exclude" to be a boolean. That way you can specify a list of fields and whether you want ONLY those or all BUT those. This makes it super easy to take advantage of the existing $var$ replacement that the field widget does and pass a url or string in as a template. Something like this:

$ diff fields_orig.js fields.js
45,46c45,46
<
<     this.exclude = this.getAttribute("exclude");
---
>     this.fieldList = this.getAttribute("fieldList");
>     this.exclude = this.getAttribute("exclude","no") === "yes";
51,53c51,53
<     var exclude;
<     if(this.exclude) {
<         exclude = this.exclude.split(" ");
---
>     var fieldList;
>     if(this.fieldList) {
>         fieldList = this.fieldList.split(" ");
55c55
<         exclude = ["text"];
---
>         fieldList = ["text"];
62c62,63
<             if(exclude.indexOf(fieldName) === -1) {
---
>             if((this.exclude && fieldList.indexOf(fieldName) === -1) ||
>              (!!this.exclude && fieldList.indexOf(fieldName) !== -1))    {
69c70,71
<             if(exclude.indexOf(fieldName) === -1) {
---
>             if((this.exclude && fieldList.indexOf(fieldName) === -1) ||
>              (!!this.exclude && fieldList.indexOf(fieldName) !== -1))    {



On Monday, February 3, 2014 3:41:02 PM UTC-5, Jeremy Ruston wrote:

Blake Blacksmith

unread,
Nov 16, 2014, 12:55:43 AM11/16/14
to tiddl...@googlegroups.com, jeremy...@gmail.com
What is the status of adding transcluded text into strings? I for instance need to transclude a title as part of the tag to search for in a filter.

I want to use the title of a tiddler to make a file path link so i have something that boils down to: [[Link|file:./root/{{!!title}}.pdf]] how can i get a string concatenation of "file:./root/",{{!!title}}, and ".pdf" so that I can automatically link files to my tiddler based on its title? 


Another related instance, I have the filter: [tag[{{!!title}}]] and I want to make a list based on it but cannot currently with: <$list filter="[tag[{{!!title}}]]">

-Blake

On Monday, February 3, 2014 3:41:02 PM UTC-5, Jeremy Ruston wrote:

Danielo Rodríguez

unread,
Nov 16, 2014, 3:20:53 AM11/16/14
to tiddl...@googlegroups.com
Hello Blake ,

This has been discussed several times. You have to use a macro definition. Since I'm on my mobile I can't provide you an example but searching for concatenate in the forum should give you some results.

PMario

unread,
Nov 16, 2014, 8:39:17 AM11/16/14
to tiddl...@googlegroups.com, jeremy...@gmail.com

Blake Blacksmith

unread,
Nov 16, 2014, 1:50:59 PM11/16/14
to tiddl...@googlegroups.com

I am able to concatenate using a macro two strings for example:

\def concatenate(string 1:"", string2:"")

$string1$$string2$

\end

<<concatenate "my" "_car">>

gives me: "my_car"

but when I use a transcluded text:

<<concatenate "my" {{!!text}}>>

I get: "my{{!!text}}" instead of the text field's string which is "_car"

Is there a way to convert a field to a usable string?

Stephan Hradek

unread,
Nov 16, 2014, 2:23:55 PM11/16/14
to tiddl...@googlegroups.com


Am Sonntag, 16. November 2014 19:50:59 UTC+1 schrieb Blake Blacksmith:

<<concatenate "my" {{!!text}}>>

Did you try to use $macrocall?

Blake Blacksmith

unread,
Nov 16, 2014, 9:13:52 PM11/16/14
to tiddl...@googlegroups.com
No I did not and I think thats doing the trick. Thanks!

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/2_L_vTJ1Zbs/unsubscribe.
To unsubscribe from this group and all its topics, 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/d/optout.

Tobias Beer

unread,
Nov 17, 2014, 3:05:48 AM11/17/14
to tiddl...@googlegroups.com
Did you try to use $macrocall

How exactly and why would that do the trick?

Best wishes, Tobias.

Danielo Rodríguez

unread,
Nov 17, 2014, 5:18:28 AM11/17/14
to tiddl...@googlegroups.com

Because it allows things like this

<$macrocall $name="themacro" something={{!!title}}/>

That is not possible with the normal call.

Tobias Beer

unread,
Nov 17, 2014, 5:39:16 AM11/17/14
to tiddl...@googlegroups.com
Ok, so the actual code for Blake to use becomes...

<$macrocall $name="concatenate" string1="my" string2={{!!title}}/>

Correct?

I'd also be interested to know why widgets can use variables and evaluated bits and direct macro calls cannot.

Best wishes, Tobias.

PMario

unread,
Nov 17, 2014, 6:57:04 AM11/17/14
to tiddl...@googlegroups.com, Jeremy Ruston
On Monday, November 17, 2014 11:39:16 AM UTC+1, Tobias Beer wrote:
Ok, so the actual code for Blake to use becomes...

<$macrocall $name="concatenate" string1="my" string2={{!!title}}/>

Correct?

yes.
 

I'd also be interested to know why widgets can use variables and evaluated bits and direct macro calls cannot.

As I did understand Jeremy from other responses, its mainly a performance decision.

-m

Jeremy Ruston

unread,
Nov 17, 2014, 9:46:13 AM11/17/14
to PMario, TiddlyWiki
I'd also be interested to know why widgets can use variables and evaluated bits and direct macro calls cannot.

As I did understand Jeremy from other responses, its mainly a performance decision.

It's actually historical. The angle bracket syntax for macros was first implemented early on, before transcluded attributes. Then as the widget syntax evolved it was clear that it was more flexible and extensible. Internally, everything is a widget, even plain text. All the wikitext syntax beyond the widget syntax is really just a series of shortcuts for more easily typing widgets and HTML. My expectation is that more and more of the basic idioms that we discover as we explore the way that widgets fit together will end up being elevated to wiki syntax. For example, we could evolve a wikitext syntax for assigning variables that is terser than the current <$set> widget.

Anyhow, the angle brackets syntax for macro invocation absolutely could support transcluded parameters, and should probably be extended to do so.

Best wishes

Jeremy.

 

-m

Blake Blacksmith

unread,
Nov 17, 2014, 5:27:30 PM11/17/14
to tiddl...@googlegroups.com
Yes that is the working code. Sorry for not posting it I've been away from my computer.


--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/2_L_vTJ1Zbs/unsubscribe.
To unsubscribe from this group and all its topics, 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/d/optout.

Reply all
Reply to author
Forward
0 new messages