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

Support Jinja syntax in templates #1661

Open
wren opened this issue Jan 7, 2023 · 1 comment
Open

Support Jinja syntax in templates #1661

wren opened this issue Jan 7, 2023 · 1 comment
Labels
enhancement New feature or request 📌 This can't go stale
Milestone

Comments

@wren
Copy link
Member

wren commented Jan 7, 2023

Use Case/Motivation

We currently allow the use of a template file to seed a new entry. This file is currently a flat text file and is taken verbatim into the editor when creating a new entry.

It would be nice to (optionally) interpret this template file using some syntax (like Jinja) to add some functionality to these templates.

This would allow the use of Jinja syntax in these templates, which would allow things like using custom fields, or making loops in the template.

Example Usage

{# templates/some-other-template-to-include.jrnl #}

Hello {{ name }}! This is a template of some sort.

{% if my_field > 32 %}
Lorem ipsum dolor sit amet.
{% else %}
Also, lorem ipsum dolor sit amet.
{% endif %}

etc

Other Information

It should be a problem, but the ability to discard an entry if the template text didn't change merits some extra consideration with this new feature to make sure nothing breaks.

@wren wren added enhancement New feature or request 🆕 New! labels Jan 7, 2023
@micahellison
Copy link
Member

I love this idea and I think Jinja is a good way to approach it.

I think the next question to figure out is: what custom fields should we support?

Some ideas:

  • journal name
  • any config value
  • custom fields in config? perhaps under a template key in the config file
  • fields passed in by command-line

@micahellison micahellison added 📌 This can't go stale and removed 🆕 New! labels Jan 14, 2023
@micahellison micahellison added this to the Backlog milestone Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 📌 This can't go stale
Projects
None yet
Development

No branches or pull requests

2 participants