Templater icon indicating copy to clipboard operation
Templater copied to clipboard

Don't Include Frontmatter in Output

Open viviengarcia opened this issue 2 months ago • 2 comments

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.

viviengarcia avatar May 05 '24 22:05 viviengarcia

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-

Zachatoo avatar May 05 '24 22:05 Zachatoo

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! :)

viviengarcia avatar May 05 '24 23:05 viviengarcia