How to use a widget for an HTML tag title?

I’ve been tinkering with the viewtemplates in tiddlywiki, and one that I am stuck on right now is the one used for displaying the modified time of a tiddler.

What I want to do is have a relative date show, but if you hover over it, it gives you the exact date. I tried to acheive this with the code below, but I may be overthinking things, because I’m not entirely sure how to add the full timestamp to the title of the span element :sweat_smile:

<$reveal type="nomatch" state="!!modified" text="" animate="yes" retain="yes">
	<span title='<$view field="modified" format="date" template={{$:/language/Tiddler/DateFormat}}/>'>
		modified: <$view field="modified" format="relativedate" template={{$:/language/Tiddler/DateFormat}}/>
	</span>
</$reveal>

Any help is appreciated, I think my brain is a bit fried haha

1 Like

I don’t know that my suggestion would be a good practice (and someone else might have a better suggestion) but here’s one idea:

<$wikify name="spanTitle" text='<$view field="modified" format="date" template={{$:/language/Tiddler/DateFormat}}/>'>
    <$reveal type="nomatch" state="!!modified" text="" animate="yes" retain="yes">
	<span title=<<spanTitle>>>
		modified: <$view field="modified" format="relativedate" template={{$:/language/Tiddler/DateFormat}}/>
	</span>
    </$reveal>
</$wikify>

Edit: However @EricShulman 's solution is more idiomatic TiddlyWiki.

You can use a filtered transclusion with the format:date filter operator and assign it as the title of a span, like this:

<span title={{{ [{!!modified}format:date{$:/language/Tiddler/DateFormat}] }}}>
	modified: <$view field="modified" format="relativedate" template={{$:/language/Tiddler/DateFormat}}/>
</span>
2 Likes

This is the better solution.

Thank you for the solution.

Looking at it, mine would have worked if I didn’t wrap my view widget in single quotes, right? Edit: (it would not lol)

( Though, I do like the format your solution is using, so I think I will go with that none the less )

Don’t just look at it, try it out! (I know this advice can be difficult for complicated ideas, but for something as simple as removing quotes from one line, I highly recommend developing the habit of experimentation.)

I’m afraid that wouldn’t be valid syntax. An HTML element (or a widget, which has the same syntax) cannot itself be the attribute value of another HTML element. (This is partly because of the ambiguity of things like />) See the documentation for a list of things that can be used as HTML attributes (you will have to scroll to the big “Attributes” heading).