Filters and prefixes

The idea is to get the contents of the ‘caption’ field on an image tiddler displayed in the current tiddler. It is all part of the issue of finding a method of displaying an image caption with the Spotlight plugin.

I am trying to get the syntax correct for this filter, but it is proving elusive:

{{{ [<storyTiddler>_images:all[]get[caption]join[ ]] }}}

or maybe this version

{{{ [<storyTiddler>_images:all[]:map[get[caption]else{!!title}]join[\n] ] }}}

I have tried various versions but they either display nothing, or have a syntax error.

In context, this filter sits inside this procedure:

<!-- also needs SQ Filters plugin -->
\procedure spotlight-actions()
<$action-spotlight
	$images={{{ [<storyTiddler>_images:all[]format:titlelist[]join[ ]] }}}
        $labels={{{ [<storyTiddler>_images:all[]get[caption]join[ ]] }}}
	$start=<<dom-src>>
/>

\end

<$eventcatcher $click=<<spotlight-actions>> selector="img" class="spotlight-mixmedia-example">

If the $labels parameter is supposed to contain a caption for each image title in the $images parameter, then this should work:

{{{ [<storyTiddler>_images:all[]] :map[{!!caption}!is[blank]else<currentTiddler>] +[format:titlelist[]join[ ]] }}} 

Tell me how it goes!

Fred

2 Likes

A step closer. The good news it excutes without an error, but it’s retrurning the path to the image file rather than the content of the caption field of the tiddler that contains it.

Looks like the _images operator automagically extracts _canonical_uri field, so we have to get back to tiddler title before getting the caption.

Try this and tell me if it works:

{{{ [<storyTiddler>_images:all[]] :map[all[tiddlers]_canonical_uri<currentTiddler>else<currentTiddler>get[caption]!is[blank]else<currentTiddler>] +[format:titlelist[]join[ ]] }}} 

I hope your tiddlers don’t include many images, as this filter might be quite slow!

Fred

Now that works! i generally only have one image in a tiddler. Now it’s working do you think it could be simplified/shortened?

I don’t know to shorten it, no. Why would you want that?

Fred

1 Like

Only if we can make it more efficient.