Templater
Templater copied to clipboard
Don't Include Frontmatter in Output
Hi, this is a proposal to have a better control over templates.
The problem
I need frontmatter in my templates for metadata, but I don't want them included in the output unless I choose to. I suppose this could be solved with user functions, unfortunately they're not available on mobile.
What I've tried
I'm currently using file.include()
to get the content of a template, which I then strip of its unwanted parts with replace()
. It works (although less handy than an internal function), but the real issue is that I don't always have the possibility to use this method.
What I propose
What is really needed is a mean to indicate Templater which part of a file is usable and which is not, per file.
A command like prune_before(direction?: bool = true)
could do it, like this:
<% tp.<internal_module>.prune_before() %>
would make Templater process content situated after the command.
<% tp.<internal_module>.prune_before(false) %>
would make Templater process content situated before the command.
This could let prune_before()
be used before and/or after the targeted content.
There's actually an existing (undocumented) way to accomplish what you want.
---
key: value
---
<%* tR = "" %>
Rest of template
Anything above the <%* tR = "" %>
line will not be added to the contents of a file.
Relevant docs for tR
: https://silentvoid13.github.io/Templater/commands/execution-command.html#how-to-output-a-value-from-a-javascript-execution-command-
Thanks for the fast reply! It's exactly what I needed! I still think a more formal way to do it would be useful but having this is already fantastic! :)