Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't Include Frontmatter in Output #1368

Open
viviengarcia opened this issue May 5, 2024 · 2 comments
Open

Don't Include Frontmatter in Output #1368

viviengarcia opened this issue May 5, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@viviengarcia
Copy link

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 viviengarcia added the enhancement New feature or request label May 5, 2024
@Zachatoo
Copy link
Collaborator

Zachatoo commented May 5, 2024

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-

@viviengarcia
Copy link
Author

viviengarcia commented May 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants