NotePlan / NotePlan/plugins

Templating: allow import name to be dynamic

Open
#514 0 comments 1 reaction 1 assignee View on GitHub

@mikeerickson is already working on this.

Since Jan 11, 2024.

Dominant language
JavaScript
Stars
204
Forks
82
Avg merge
22h 27m
Merged PRs (30d)
3

Description

A user has created a template that dynamically imports a template based on the day of the week.
What would be ideal would be to allow this import to load a template based on the calculated day, e.g.:

const daysOfWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
const today = daysOfWeek[this_date.getDay()]
const templateName = `☀️ Daily Note - ${today}`
...
<% import(`${templateName}`)  -%>

This doesn't work as the code is currently written.
The string in the import statement is treated as a literal and is not interpolated.

***************************************************************************
   ERROR
   Method: NPTemplating.getTemplate:
   Message: Template "${templateName}" Not Found or Empty
***************************************************************************

Would be nice to allow this to be dynamic so that the code above would load "☀️ Daily Note - Mon" or "☀️ Daily Note - Fri"

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.