Template that creates an automatic folder structure for every project

Hi,

can I write a template (with templater) that creates an automatic folder structure for every of my project?

Thank you for your help

This is a first concept that works:

<%*
site = “customers/Bonn, Uniklinik/”;
contacts = “contacts/”;
meetings = “meetings/”;
projects = “projects/”;

await this.app.vault.createFolder(site);
await this.app.vault.createFolder(site + contacts);
await this.app.vault.createFolder(site + meetings);
await this.app.vault.createFolder(site + projects);

%>

image

But I want to use a conditional clause, if the main folder (site) and the others exist and this doesn‘t works.

<%*
site = “customers/Bonn, Uniklinik/”;
contacts = “contacts/”;
meetings = “meetings/”;
projects = “projects/”;

if (!tp.file.exists(site)) {await this.app.vault.createFolder(site)};
if (!tp.file.exists(site + contacts)) { await this.app.vault.createFolder(site + contacts)};
if (!tp.file.exists(site + meetings)) { await this.app.vault.createFolder(site + meetings)};
if (!tp.file.exists(site + projects)) { await this.app.vault.createFolder(site + projects)};

%>

1 Like

Finally I have found a solution:

<%*
customer = “Bitburg, xxx”

site = “Kunden/” + customer + “/”;
contacts = “Kontakte/”;
meetings = “Meetings/”;
projects = “Projekte/”;

if (!(await this.app.vault.adapter.exists(site))) {await this.app.vault.createFolder(site)};
if (!(await this.app.vault.adapter.exists(site + contacts))) {await this.app.vault.createFolder(site + contacts)};
if (!(await this.app.vault.adapter.exists(site + meetings))) {await this.app.vault.createFolder(site + meetings)};
if (!(await this.app.vault.adapter.exists(site + projects))) {await this.app.vault.createFolder(site + projects)};

%>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.