mProjectsCode / mProjectsCode/obsidian-meta-bind-plugin

For View fields, to be able to define a representation of empty values

Open
#400 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
TypeScript
Stars
1k
Forks
86
PR merge metrics
No merged PRs in 30d

Description

Please fill out these Check-boxes
  • I checked for existing similar feature requests
  • I have read the docs and checked that the feature I am requesting is not already implemented
  • 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:

  1. 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]]")`
  1. 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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests; start at the VIEW field implementation for text and link rendering, using the provided frontmatter examples as cases for undefined, null, and empty-string values. Define the supported empty-value syntax and behavior for both field types, then verify the reading view produces the requested fallback text or link.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.