silverbullet icon indicating copy to clipboard operation
silverbullet copied to clipboard

Questions: frontmatter variables, migration, and inheritance

Open fuzzah opened this issue 1 year ago • 2 comments

New user here, may be misunderstanding something ;(

Can we include frontmatter variables in the same page?

Something like this:

---
tags: book
title: My title
author: Some author
---
# My review for the book {{title} by {{author}}
|^|

# Other books by this author
```query
book where author =~ /{{author}}/ render [[templates/book]]
```

Of course the point is to update them only in the frontmatter without having to change them everywhere on the page.

Can we somehow migrate pages to use newer frontmatter after template update?

If I had variables like title and author in the book template, and then decided to add something like rating or rename author to authors, I would have to manually update 100+ books I have. There's ought to be at least some helper mechanisms to migrate the old pages. We could at least use some warning like "newer template has these frontmatter changes: added field X, removed field Y, renamed field A to B, ..."

Is there some sort of frontmatter inheritance?

I'd like to define generic books, but then separate them to technical books, fiction books, etc. Inherited templates would then include some additional fields based on their kind, while having their base fields reused (and synchronized) from the parent template.

fuzzah avatar Jan 29 '24 22:01 fuzzah

Can we include frontmatter variables in the same page?

Yes, but in a slightly ugly way. You can use a template for this:

```template
template: |
    # My review for the book {{title}} by {{author}}
```

Can we somehow migrate pages to use newer frontmatter after template update?

There's no real tools for this yet, but feel free to a GH issue to request this. However, since this is all markdown files on a disk, you can use any other tools to achieve this. If you're comfortable with VS Code, you may want to do a folder-wide search and replace for instance.

Is there some sort of frontmatter inheritance?

Do you have a concrete example? You're looking to inherit actual data?

zefhemel avatar Jan 30 '24 08:01 zefhemel

@zefhemel , the "template template" didn't work for me:

  1. Seems to only insert @page.name, but other fields such as author or title are left blank, as they are blank in the frontmatter when I instantiate the template.
  2. Seems to not reflect changes made to any fields, even @page.name. The nested template just contains text without any variables in it.

To clarify: I wanted it to be inside of a book template like so:

---
tags: template
hooks.snippet.slashCommand: new-book
hooks.newPage:
      suggestedName: "books/"
      forPrefix: "books/"
frontmatter: |
  tags: book
  author: 
  rating: 5
  format: printed
  publishYear: 
---

```template
template: |
  # My review for {{@page.name}} by {{author}}
```
## About
|^|

## Main ideas

## Quotes

## My opinion

## Other books by this author
````template
template: |
  ```query
  book where author =~ /{{author}}/ render [[templates/book]]
  ```
````

Back to [[index]]
Edit this template [[templates/new-book]]

I removed the title field, as I realized that the page name is the title. About the last template here: I tried multiple variants, but can't make the "other books by this author" thing to work.

Regarding template and frontmatter inheritance: I don't want to copy the actual data from parent templates, only the structure of their frontmatter (variables' names) and the page contents. Another example for that: a generic book has the author, publishYear, and rating fields. But then text books would have pageCount, while audio books would have duration. It would be hard to maintain and pretty redundant to enumerate all the parent fields in each template to only change one variable. We can further divide books by genre, and even if their templates would all have the same frontmatter, they could still have different text structure.

P.S. I'd like to see how people really use SB, maybe it would lift a lot of questions from me. The YT tutorials are only showing basic stuff, but it would be interesting to see how people actually define their templates, frontmatters, and other stuff for actual long-term use of SB with comfort.

fuzzah avatar Jan 30 '24 09:01 fuzzah