obsidian-meta-bind-plugin
obsidian-meta-bind-plugin copied to clipboard
For View fields, to be able to define a representation of empty values
Please fill out these Check-boxes
- [X] I checked for existing similar feature requests
- [X] I have read the docs and checked that the feature I am requesting is not already implemented
- [X] My feature request consists of only one feature
Is your Feature Request related to a Problem or Annoyance?
I use Templater logic when creating new documents. For example, it might look like this:
<%*
let documentType = await tp.system.suggester(/* Logic to return one of the options */);
if (documentType == 'country') {
countryCode = await tp.system.suggester(/* Logic to return one of the contry codes */);
countryLink = `[[country--${countryCode}]]`;
} else {
countryCode = ''; // or undefined, or any of the acceptable "empty" values.
countryLlink = '';
}
Then in the frontmatter:
---
CountryCode: "<% countryCode %>"
CountryLink: "<% countryLink %>
---
And, finally, on the page:
`VIEW[{CountryCode}][text]`
`VIEW[{CountryLink}][link]`
Now, if I use underfined
or null
as an empty value, the VIEW won't look as expected.
For example, the next Templater template with product the following result:
<%*
let countryCode;
let countryLink;
-%>
<% "---" %>
countryCode: <% countryCode %>
countryLink: "<% countryLink %>"
<% "---" %>
`VIEW[{countryCode}][text]`
`VIEW[{countryLink}][link]`
Resulting markup in Editing view:
---
countryCode: undefined
countryLink: "undefined"
---
`VIEW[{countryCode}][text]`
`VIEW[{countryLink}][link]`
and in Reading view:
undefined
[undefined](app://obsidian.md/undefined)
Describe the Feature you'd like
I would like the Plugin to be able to do 2 things:
- To have a parameter in the field type to show instead the empty values, e.g.:
%% A visual representation of a missing value %%
`VIEW[{countryCode}][text(emptyText="N/A")]`
%% Similar to the option above %%
`VIEW[{countryLink}][link(emptyText="N/A")`
%% A link to some other page, e.g., with explanation page/note, why this value is empty.
`VIEW[{countryLink}][link(emptyLink="[[missing country code note|N/A]]")`
- Essentially, it would be cool if logic implemented with the following Templater code could be replicated with meta-bind for dynamic templating.
<%* if (countryCode) { %>
- **Country Code**: `VIEW[{countryCode}][text]`
- **Country Info note**: `VIEW[{countryLink}][link]`
<%* } else { %>
- **Country Info**: Not Applicable
<%* } %>
This feels like a feature of a dynamic templating based on frontmatter properties, which I'm not sure MetaBind would like to step in that direction. Maybe, some other plugins, e.g., based on Handlebars templating language would better with (Currently, not many sensible plugins to choose from).
But with VIEW
fields, MetaBind is already dealing with conditional data presentation, why not extend current capabilities?
Alternatives
Currently, I return empty strings (""
) to populate the frontmatter and eventually to be presented by MetaBind VIEW[]
, as it is less ugly than "null" or "undefined" strings.
Still have to figure out if the following plugin is worth any effort to be used for this kind of tasks:
obsidian://show-plugin?id=obsidian-handlebars
Additional Context
No response