Replies: 1 comment
-
This is the method I use, documented here. Is this what you're looking for? Pasting template here, for longevity. <%*
// Fallback template if no type is selected
let template = 'default-template';
// Get list of folder templates (setup in Templater settings)
const folderTemplates = app.plugins.plugins['templater-obsidian'].settings.folder_templates;
// Get default path for new files
const newFileLocation = app.vault.getConfig("newFileLocation");
const defaultNewFilePath = newFileLocation === "folder"
? app.vault.getConfig("newFileFolderPath")
: "";
// If note is in default note location (likely from quick switcher)`
if (tp.file.folder() === defaultNewFilePath) {
// Prompt for folder template
const selectedTemplate = await tp.system.suggester(folderTemplate => folderTemplate.folder, folderTemplates);
// If folder template is selected and is not the picker template,
const pickerTemplateFolder = '/';
if (selectedTemplate && selectedTemplate.folder !== pickerTemplateFolder) {
// Move file to folder template and set template to apply
template = selectedTemplate.template;
await tp.file.move(`${selectedTemplate.folder}/${tp.file.title}`);
}
}
// Apply template
tR += await tp.file.include(`[[${template}]]`)
_%> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How it is possible to create a new file with defined template when I click on a specific link in some "index" file (like in Wiki - when the file does not exists it it created a new one)?
I have many folders set with Templater. When I create a new file in those folders I set in the Templater Option which template in which folder should be used. This is OK.
The problem is that I have too many folder and I want to hide them from File list view. So, I want to create let say "index for new files" with links to new file like https://www.reddit.com/r/ObsidianMD/comments/101gfg2/is_there_a_way_to_create_a_new_file_from_within_a/ . The problem is that it will create file in the same folder as is the index file and not in a wanted.
I found some solution with Templater
https://forum.obsidian.md/t/click-link-to-create-new-file-with-prompt-to-use-template/31798 but it depends on another plugin and it is quite difficult for me.
Is there some easier way?
Beta Was this translation helpful? Give feedback.
All reactions