Hello everybody. Some days ago I released the version 1.33.0 of the plugin.
This one has some quality of life improvements that I’m particularly proud of, because they are simple yet powerful.
This two new features are focused on easing the usage of results within templater templates. Both features build on top of each other, so I will present first the base one, how to use it and then how the second one makes it even better.
The first new feature is a new method on the Result object which returns a smart value:
getValue('field-name') => ResultValue
This method lets you get a single value from the result set, but instead of returning just the value, it will return a “smart object” that has some nice additional methods and features. Let’s see it with some examples.
For the rest of the post, all of the examples here assume the following template header:
<%*
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('simple', {values:{
list:['1984','Hello'],
name: 'Fedever',
number: 55
}});
%>
Let’s start wit something simple, you want to render the name
field of the form, you can do it like this:
<% result.getValue('name') %>
As I said, the returning value is “smart” and can be automatically converted to a string so this will render properly. This method can also be accessed using a sorthand, so the following is exactly the same if you are one of the ones that likes typing less 
<% result.getV('name') %>
What about the more complex value list
? There is when things start to get interesting. Let’s say you want to render it as a string of comma separrated values. All you need to do is:
<% result.getV('list') %>
Simple, right? Let’s make it more interesting. What if you want it as a bulleted list? Here you go:
<% result.getV('list').bullets %>
Nice right? Ok, Ok, now I want it all uppercase bullet list! Still nice and short!
<% result.getV('list').upper.bullets %>
Now let’s assume you make a mistake, and try to access a value that does not exist in the result set, what will happen if you do this?
<% result.getV('invalid').upper.bullets %>
As I said, both the method and the resulting the object is smart so nothing will happen! It will just output a empty string, and that is all.
If you want to explore even more available methods, take a look at the specific docs here.
Now time for the second and also esciting new feature:
result values shorthand
The previous examples were nice and short, but you still need to type too much for my taste: the method getValue
, the parenthesis, the string opening and closing and only then the field-name you are interested in. We can do better!
the result
Data Proxy
Building on the convenience of getValue
, I’ve introduced an even more streamlined way to access your form data: a proxy for result data values. This feature marries perfectly with the functionality of ResultValue
, enabling tidier and more intuitive template code.
Let’s revisit our examples, this time employing the new proxy access:
For accessing the name
field, instead of using getValue
or its shorthand getV
, you can now directly use:
<% result.name %>
This is not only shorter but also clearer! It directly reflects what you’re trying to access without any additional function calls or string literals.
As for the list
field, remember how we got a comma-separated string? Now it’s as simple as:
<% result.list %>
And for those fancier requirements like an uppercase bullet list? Just as easy:
<% result.list.upper.bullets %>
What if you attempt to access a non-existent field like ‘invalid’? No worries there either:
<% result.invalid.upper.bullets %>
You’ll receive an empty string, just as before. No errors thrown, no interruptions—your templating flow remains smooth and error-tolerant.
By employing this proxy to interact with your form data, you can write cleaner and more concise templates that are easier to read and maintain. Say goodbye to unnecessary verbosity!
For further information on how to harness the full potential of this feature, please refer to the documentation here.
That’s all for today! I hope these updates make your work with Obsidian Modal Form plugin more enjoyable. Happy templating!