Am 17.09.2014 02:43, schrieb Michael Evans:
Is there a way for me to pass a caption to the ModalImage tiddler in
addition to the image source?
Hi Michael,
yes it is possible using the same kind of approach but in my opinion it
gets pretty ugly then. Nevertheless there are two possibilities that I
can think of:
*#1 The persistent one*
Create a tiddler called |$:/lightBox/currentImage| and set its type to
'Data Dictionary'.
Then the macros can be redesigned like this:
|\define lightBox(img, caption, template)||
||<$button message="tm-modal" param="$template$"
set="$:/lightBox/currentImage" setTo="||
||img: $img$||
||caption: $caption$">||
||
||[img width="100" [$img$]]||
||</$button>||
||\end||
||
||\define lightBoxWithFixedTemplate(img, caption)||
||<<lightBox "$img$" "$caption$" "ModalImage">>||
||\end|
Of course you would also have to change your template to include a caption:
|<img src={{$:/state/currentImage##img}} />||
||
||{{$:/state/currentImage##caption}}|
*#2 The somewhat pretty one*
Some time ago Matabele published a set of various useful widgets that
are capable of emitting messages. In particular, one could redesign the
lightbox macro with help of his SetField widget:
|\define lightBox(img, caption, template)||
||
||<$setfield tiddler="$:/state/currentImage" set="!!caption"
setTo="$caption$" message="tm-modal"||
||param="$template$">||
||<$setfield tiddler="$:/state/currentImage" set="!!img" setTo="$img$">||
||<$button message="tw-set-field">||
||
||[img width="100" [$img$]]||
||</$button>||
||</$setfield>||
||</$setfield>||
||\end|
This time I also feel much more comfortable using $:/state/currentImage
for that, since it does not have to be setup first and only carries
state information. In your template you can access the image-url and the
caption like this:
|<img src={{$:/state/currentImage!!img}} />||
||
||{{$:/state/currentImage!!caption}}|
/Andreas
P.S.: Thanks Jeremy :D
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.