Hi folks!
I am stuck with something which is probably obvious if you know how …
<$select tiddler='mywotd'>
<$list filter='[[wotd]indexes[]]'>
<option value='[[wotd]getindex<title>]'><$view field='title'/></option>
</$list>
</$select>
{{mywotd}}
I would like to show the definition of a word after selecting it from a dropdown list. I have the list but the definition does not appear in “mywotd” - instead it shows:
[[wotd]getindex
Thanks
M
To get the index value, use a “filtered transclusion” as the parameter, like this:
<option value={{{ [[wotd]getindex{!!title}] }}}>
-e
I may need to rethink my approach here but is there a way to append text to the expression:
<option value={{{ [[wotd]getindex{!!title}] }}}>
What I would really like to write to the “mywotd” tiddler is:
My word for today is {WORD} meaning {DEFINITION}.
I can then paste this to Bluesky, X etc.
Many thanks
M
This should do it:
<option value={{{
[[My word for today is "]]
[{!!title}]
[[" meaning "]]
[[wotd]getindex{!!title}]
[[".]]
+[join[]]
}}}><$view field='title'/></option>
Remove the quotes if you don’t want them. And format this as you choose as a single line or as multi-line like I did.
If you find the filter syntax difficult to read, you can also do the same thing a bit more legibly with a substituted attribute value:
<option value=`My word for today is "${ [{!!title}] }$" meaning "${ [[wotd]getindex{!!title}] }$".`>
<$view field=title />
</option>
Within the backticks (not quote marks!) that indicate the substitution syntax, anything wrapped in ${ }$ will be evaluated as a filter, anything in $(variable)$ format will be replaced with the value of the corresponding <<variable>>, and anything else will be preserved as a literal string — including any spaces. This lets us omit the brackets and the +[join[]] step necessary in the filtered transclusion.
Yes, that’s much nicer. I don’t know why sometimes I remember to use this and sometimes don’t!
I do this by thinking of the “backticks as attribute values” as one of the best ways to “craft a string, concatenate, substitute values. including with filters” to give us a value.
- Perhaps with the next best being using functions (may need join), but the function is defined at the top in pragma and not in-line.
- In part because define, which can be used for substitution, is deprecated and along with procedures is not evaluated until the final render (unless you used wikify/transclude)
Backticks as attribute values;
- As a result it is great for constructing a filter string, tooltip etc… from parts to give to a parameter.
- And also its ability to be used against html tag attributes as readily as with widgets etc…
- Keep in mind you can also use it to set variables set/let/vars
I think I will publish a Tip on this.
Just for chuckles, here’s the data tiddler I used when testing this:
onomatopoeia: just what it sounds like
monosyllabic: no it's not
phonetic: really should begin with an "F"