Concatenate transclusion as link?

67 views
Skip to first unread message

人云E云

unread,
Aug 6, 2018, 4:25:31 PM8/6/18
to tiddl...@googlegroups.com
Hi guys,

I'm a little new to tiddlywiki, and find some functionalities don't work as I thought, including macro call and transclusion.

The background is that I have a DataTiddler, which stores the baseurl of the site (when published); let's call this `dt##baseurl`. I have a feed plugin installed to generate atom feed, under `/atom.xml`, relative to the baseurl. (Some may suspect I intend to make this site like a blog, and you are right.)

When I need to concatenate these two pieces of text together, as mentioned elsewhere (e.g. official site), I need to use a helper macro to establish the real concatenation of transclusion and string literal. (But I still don't know why... Is this because of the processing engine's execution order / lifecycle?)
I succeeded to do this when using text as the visible content, through `[[$text$|$baseurl$/atom.xml]]`.

However, when I want to create a image which links to the atom feed, I find no solution.
I have to use `<a href=... >[img[MY_IMG]]</a>` for this to work (LinkWidget will link to tiddler only; `[[]]` syntax only works on text). But if I apply the previous trick, neither of the follow methods work.

Method 1:

```
  \define atomfeed(burl) $burl$/atom.xml
  <a href=<$macrocall $name=atomfeed burl={{dt##baseurl}} />>[img[MY_IMG]]</a>
```

The $macrocall widget won't really work, and the resulting line is broken. I guess this is because of the `/>`.

Method 2:

```
  \define atomfeed(burl) $burl$/atom.xml
  <a href=<<atomfeed {{dt##baseurl}}>>>[img[MY_IMG]]</a>
```

The macro will be evaluated, but the transclusion won't, resulting in a link to "{{dt##baseurl}}/atom.xml".

Method 3:

```
  \define atomfeed(burl) $burl$/atom.xml
  \define wrapatomfeed() <$macrocall $name=atomfeed burl={{dt##baseurl}} />
  <a href=<<wrapatomfeed>>>[img[MY_IMG]]</a>
```

The macro will be evaluated once, but the second macrocall won't be evaluated at all.


I also tried a few other combinations of these methods (e.g. replace the 3rd method's wrap macro content to `<< >>`), but none of them worked.
Anyone has any ideas?

Mat

unread,
Aug 6, 2018, 5:30:27 PM8/6/18
to TiddlyWiki
While I didn't study your description in detail, my spontaneous thought is that you can try to use the WikifyWidget at some point before calling the macro, i.e

<$wikify name=foo text=<<atomfeed {{dt##baseurl}}>> />

...and then, inside the macro, you can call for this by using

$(foo)$

Another approach is to nest macros so that things evaluate gradually. That $(foo)$ syntax is a pretty powerful way to invoke a variable that was defined outside of the current macro.

<:-)


Mark S.

unread,
Aug 6, 2018, 6:07:56 PM8/6/18
to TiddlyWiki
A widget is a kind of super power html tag. So #1 won't work because you can't embed an html tag inside of an html tag.

#2 ... sorta kinda ought to work. But I avoid using <<>> macro notation with a parameter because so often it doesn't. I think it's because it wants and expects an actual string as the parameter, not an object to be rendered.

Transclusions and (plain) macros do get rendered inside of widgets before being used by the widget.

So, I think this variation should work:

\define atomfeed(burl)<a href="""$burl$""">[img[MY_IMG]]</a>
          <$macrocall $name=atomfeed burl={{dt##baseurl}} />

Good luck!
-- Mark

Mat

unread,
Aug 6, 2018, 7:10:08 PM8/6/18
to TiddlyWiki
Mat wrote:
While I didn't study your description in detail, my spontaneous thought is that you can try to use the WikifyWidget at some point before calling the macro, i.e

<$wikify name=foo text=<<atomfeed {{dt##baseurl}}>> />


(Doh! Did I write that?) You (or me for that matter) must not write shortform commands such as <<...>> (for macrocalls) and {{...}} (for transclusions) inside one another. So the above must be evaluated one at a time, or by nesting macros like I mentioned. I.e you set(widget) something to be that transclusion value and then you call for another macor that contains

<$wikify name=foo text=<<atomfeed "$(yoursetvalue)$">> />


<:-)

Mat

unread,
Aug 6, 2018, 7:13:20 PM8/6/18
to TiddlyWiki
Mark S. wrote:
A widget is a kind of super power html tag.

That's a good description I haven't heard before!

<:-)
Reply all
Reply to author
Forward
0 new messages