Macro with transclusion from datatiddler

179 views
Skip to first unread message

Magnus

unread,
Dec 23, 2018, 12:19:21 PM12/23/18
to TiddlyWiki
I'm a total noob but I have this macro for display external images and I'm trying to add the information from a data-tiddler (application/x-tiddler-dictionary) but this is not working.

\define lightBox(img, caption, photographer, template)
<$button message="tm-modal" param="$:/_template/lightBox"  set="$:/_state/currentImage" setTo="
caption: $caption$
photographer: $photographer$">

{{$:/_dictionary/photographers##$photographer$}}
</$button>
\end

Mark S.

unread,
Dec 23, 2018, 2:38:46 PM12/23/18
to TiddlyWiki
When you say it doesn't work, what do you mean? What did you expect it to do, and what did it do instead?

Good luck!
-- Mark

Magnus

unread,
Dec 23, 2018, 4:18:24 PM12/23/18
to TiddlyWiki
I expected it to set the state-tiddler $:/_state/currentImage with the feched index for <<currentTiddler>> from the data-tiddler $:/_dictionary/photographers like $img$ and $caption$ but I get nothing

TonyM

unread,
Dec 23, 2018, 5:14:54 PM12/23/18
to TiddlyWiki
Magnus,

Perhaps you need to show the call to this macro and how you are iterating through your items in the data tiddler/image tiddlers. It is the invocation of the macro that populates the $variables$ and alters the currentTiddler.

Regards
Tony

Mark S.

unread,
Dec 23, 2018, 5:49:17 PM12/23/18
to TiddlyWiki
This is a case where you need to call a macro inside a macro, because you want to embed $photgrapher$ and then get the result and embed that. So there's two levels of concatenation.

This works for me:

\define lightBox(img, caption, photographer, template)
<$macrocall $name=lightBox2 img="$img$" caption="$caption$" photographer={{$:/_dictionary/photographers##$photographer$}} template="$template$"/>
\end
\define lightBox2(img, caption, photographer, template)

<$button message="tm-modal" param="$:/_template/lightBox"  set="$:/_state/currentImage" setTo="
img: https://raw.githubusercontent.com/magev958/Images/master/$img$.jpg
caption: $caption$
photographer: $photographer$"
>

[img [https://raw.githubusercontent.com/magev958/Images/master/$img$.jpg]]

$photographer$
</$button>
\end

<$macrocall $name=lightBox img="Motovun Jack.svg" caption="Myphoto is nice" photographer=tom template="stuff"/
>

You of course would call whatever your photographer's short name is ;-)

-- Mark

Magnus

unread,
Dec 23, 2018, 7:27:40 PM12/23/18
to TiddlyWiki
I'm new to TW so not really sure how to work with macro but I made a showcase at http://magnus.playground.tiddlyspot.com/ if that helps.

Magnus

unread,
Dec 23, 2018, 7:29:32 PM12/23/18
to TiddlyWiki
Thanks for your suggestion but I can't get this either to work, the photographer variable does not show 

TonyM

unread,
Dec 23, 2018, 8:39:35 PM12/23/18
to TiddlyWiki
Did you try photographer="name with spaces" or photographer="""name with quotes and spaces"""

Mark S.

unread,
Dec 23, 2018, 10:03:08 PM12/23/18
to TiddlyWiki
Hi Magnus,

There was a lot, lot more going on in your site than you indicated ;-)

After making a backup, drag, drop, and import the attached.

I've changed your image state tiddler to a regular tiddler and reference it's fields instead of using it as a data dictionary. You can change this if you want later, but you will have to make an action-setfield for every index you want to create, whereas doing it my way you only need one.

Part of the problem was that you were trying to do two things with one Button. You were trying to launch a modal, and you were trying to set (I think) field indexes.  You were also trying to do all that with a single string. Not sure if that's possible but it was an interesting approach To do two things at once, you need to use the "actions" attribute. The action-setfield widget will let you set multiple fields at once with one widget, so that's what I used. But it won't let you set multiple indexes in a data dictionary at once.

I've turned off your old macro for now, but you can change things later if you want.

Have fun
-- Mark
tw_magnus_photo_gallery.json

@TiddlyTweeter

unread,
Dec 24, 2018, 5:52:56 AM12/24/18
to TiddlyWiki
Magnus & Mark S.

Very interesting thread.

It kinda pins down the issue of how to do galleries. 

Magnus is better than he thinks he is.

Regarding galleries I can't do the code but can comment on different approaches ...

-- The one by one Tiddler method (excellent detail)

-- Via Data Tiddler (compact)

-- Via auto-generated number (good for very large photo sets that are numbered sequentially ... meta-data is more complex, but you don't need any specific Tiddlers for the images).

Josiah

Magnus

unread,
Dec 25, 2018, 10:51:50 AM12/25/18
to TiddlyWiki
There was a lot, lot more going on in your site than you indicated ;-)
 
Yeah I have been adding pieces for a some time :) Trying to streamline it right now
 
I've changed your image state tiddler to a regular tiddler and reference it's fields instead of using it as a data dictionary. You can change this if you want later, but you will have to make an action-setfield for every index you want to create, whereas doing it my way you only need one.

Part of the problem was that you were trying to do two things with one Button. You were trying to launch a modal, and you were trying to set (I think) field indexes.  You were also trying to do all that with a single string. Not sure if that's possible but it was an interesting approach To do two things at once, you need to use the "actions" attribute. The action-setfield widget will let you set multiple fields at once with one widget, so that's what I used. But it won't let you set multiple indexes in a data dictionary at once.

Thank you very much for your explanation, I feel I have a much better understanding of the mechanics of the macro :) It works perfectly 

Mohammad

unread,
Feb 8, 2019, 12:28:54 AM2/8/19
to TiddlyWiki
Hello Magnus,
 Your playground wiki is really great and worth to be indexed by David Gifford.

The way you organized the materials and the TW code snippets you used to display contents, and the lighbox for images are great.
It has a lot of things to be learned and practiced for TiddlyWikians.

For whom interested see:


--Mohammad
Reply all
Reply to author
Forward
0 new messages