Template Filtering?

Is it possible to filter templates?

What I mean:

  • the quick note template is great that comes in Core, but I dislike the suggested title. I want it to say Quick Note instead of Inbox.
  • easy enough I could just create m’own template and use that. But then, I would either have to disconnect from Core/Quick Note, or, live with the fact to have 2 quick note templates
  • so the spoiled PHP/WP developer mind of mine asks for a filter :stuck_out_tongue: where I can filter suggestedName: "Inbox/{{today}}/{{safeTime}}" and change it to suggestedName: "Quick Note/{{today}}/{{safeTime}}"

I figured this is not possible atm, however, is it somehow considered, planned?
You might ask why I don’t just create the own template and unsubscribe from the core one: well, because if cool stuff like this is getting updates, I want them :grin: along my customizations.

Not sure if filtering is the right word for what you’re trying to do, or maybe I misunderstand.

You can change the suggested name for the template, does that work?

The actual template is in Library/Core/New Page/Quick Note

One way to handle this is to use Page: Copy on the current template, and copy it to Library/Personal/New Page/ or somewhere instead of Library/Core, and then update your libraries key in SETTINGS to exclude that template:

libraries:
- import: "[[!silverbullet.md/Library/Core/*]]"
  exclude:
  - "[[!silverbullet.md/Library/Core/New Page/Quick Note]]"

When you run the libraries update command, it’ll delete what you have excluded so you shouldn’t end up with duplicates.

3 Likes

Right, but then when upstream adds some awesomeness to it I wouldn’t get that update

„Filtering“ would literally mean to use the original, pass it through a filter and return custom

Filter not as in search but as in this dummy code using somewhat phpish syntax which is about the only I know:

$original = 'the original template here';
return awesome_hook('hook_name', $original);
……..
function my_filter($original){
$modified_original = // do whatever to modify $original
return $modified_original;
}
add_awesome_hook('hook_name', 'my_filter');

And this would then use my modified original.
And still leave the rest (which I didn’t modify) as is.

For reference perhaps the WP doc can help understand the idea better:

But I’ll stick with your approach, and just check from time to time what’s been updated and if I can use what’s new.

There was some discussion here on this topic: Brainstorm: Library sharing - #5 by zef

Ultimately I decided to go with the simplest viable solution and see how it would work out for people. That is: just override all templates on every library update, and let people exclude specific templates and maintain their own copies. We can do fancier things like filters, overlays and other stuff and maybe we will at some point as this functionality is more heavily used. It does add complexity, and in places it’s already hard to understand why different things do or do not happen. Adding more complexity would only make that worse. We’d need a debugger tool of some sort :slight_smile:

1 Like

Makes sense to me. I was rather wondering if it is possible as in “do I miss something” than asking for it to be implemented.
In the end those templates are not (yet) massive with hundreds of lines of content to manage so if someone wants, it is really quick to “merge”, and even, one could probably host the templates on git, then do a pull from it instead of directly pulling them into their SB instance from the source. This after merging adequately whatever updates came into the GitHub. This way version control amendments can be kept.

But I figured that it really hasn’t been necessary so far, the only template I wanted to amend is the quick notes, and that is truly short so no issue to re-amend in future.

Thanks!

1 Like

I wonder if one could somehow use the git plug (haven’t used it yet) to merge a customized template into the core template after an update.

At the very least you could do it manually but would have to check regularly if something changed, I guess.

I would fork the original GitHub (or just the libs silverbullet/website/Library at main · silverbulletmd/silverbullet · GitHub), and whenever that repo is saying its out of sync, pull in the upstream and resolve any merge conflicts if any.
That should keep your local fork with your changes, and you should be able to pull the libs from your own custom url (probably you will have to clone your own repo into either a local or online instance since SB probably is not able to pull from a GitHub folder)

It needs some testing, this is just writing top off my head.