Giter Site home page Giter Site logo

Comments (2)

McGlear avatar McGlear commented on August 14, 2024 1

I assume you don't have only daily notes within periodic exclusively, and therefore don't want daily-template.md to be applied to all notes you create within (a subfolder of) periodic?
If so: You can create a "Meta template" and outsource your pattern matching into javascript code within that meta template file. Then include the appropriate template (daily-template.md, monthly-template.md, etc.) based on what the Meta Template matches to.

Simple example that assumes Daily Notes are always named "Daily Note YYYY-MM-DD"

<%*
if (tp.file.title.startsWith("Daily Note")){
  tp.file.include("[[daily-template.md]]")
} else {
  tp.file.include("[[generic-periodic-template.md]]")
}
%>

You can get creative with how to identify the correct template:

  • you could get the note's parent folder and match that folder's name to different date formats using string-matching or regex
  • You could make use of javascripts date objects and turn folder paths into dates, then select the appropriate template based on that
  • you could include a fallback that prompts a user input if no condition was matched and lets the user choose what kind of periodic note it is
  • ...

Good Luck :)

from templater.

Riffaells avatar Riffaells commented on August 14, 2024

Thank you very much, here I understood, that is, it was possible to specify the default template. And it will all work, true slower, but yes okay:

<%*
const folderPath = tp.file.folder(true);

const yearPattern = /(\d{4})y/;
const quarterPattern = /(\d{4}-Q[1-4])/;
const monthPattern = /(\d{4}-\d{2})/;
const weekPattern = /(\d{4}-W\d{2})/;
const dayPattern = /(\d{4}-\d{2}-\d{2})\.md$/;

const isYear = yearPattern.test(folderPath);
const isQuarter = quarterPattern.test(folderPath);
const isMonth = monthPattern.test(folderPath);
const isWeek = weekPattern.test(folderPath);
const isDay = dayPattern.test(folderPath);

if (isDay) {
  tR += await tp.file.include("[[daily-template]]");
} else if (isWeek) {
  tR += await tp.file.include("[[weekly-template]]");
} else if (isMonth) {
  tR += await tp.file.include("[[monthly-template]]");
} else if (isQuarter) {
  tR += await tp.file.include("[[quarterly-template]]");
} else if (isYear) {
  tR += await tp.file.include("[[yearly-template]]");
}
%>

from templater.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.