( filePath: string, resolvedTemplatePath: string )
| 574 | } |
| 575 | |
| 576 | protected async createFileWithTemplate( |
| 577 | filePath: string, |
| 578 | resolvedTemplatePath: string |
| 579 | ) { |
| 580 | try { |
| 581 | const templateContent: string = await this.getTemplateContent( |
| 582 | resolvedTemplatePath |
| 583 | ); |
| 584 | |
| 585 | // Extract filename without extension from the full path. |
| 586 | const fileBasename = basenameWithoutMdOrCanvas(filePath); |
| 587 | this.formatter.setTitle(fileBasename); |
| 588 | // {{FOLDER}} in the body reflects the file's actual on-disk folder. |
| 589 | this.formatter.setTargetFolderPath(parentFolderPath(filePath)); |
| 590 | |
| 591 | const formattedTemplateContent: string = |
| 592 | await this.formatter.withTemplatePropertyCollection(() => |
| 593 | this.formatter.formatFileContent(templateContent), |
| 594 | ); |
| 595 | |
| 596 | // Get template variables before creating the file |
| 597 | const templateVars = this.formatter.getAndClearTemplatePropertyVars(); |
| 598 | |
| 599 | log.logMessage(`TemplateEngine.createFileWithTemplate: Collected ${templateVars.size} template property variables for ${filePath}`); |
| 600 | if (templateVars.size > 0) { |
| 601 | log.logMessage(`Variables: ${Array.from(templateVars.keys()).join(', ')}`); |
| 602 | } |
| 603 | |
| 604 | const suppressTemplaterOnCreate = filePath |
| 605 | .toLowerCase() |
| 606 | .endsWith(".md"); |
| 607 | const createdFile: TFile = await this.createFileWithInput( |
| 608 | filePath, |
| 609 | formattedTemplateContent, |
| 610 | { suppressTemplaterOnCreate }, |
| 611 | ); |
| 612 | |
| 613 | // Post-process front matter for template property types BEFORE Templater |
| 614 | if (shouldPostProcessFrontMatter(createdFile, templateVars)) { |
| 615 | await postProcessFrontMatter(this.app, createdFile, templateVars); |
| 616 | } |
| 617 | |
| 618 | // Process Templater commands for template choices |
| 619 | await overwriteTemplaterOnce(this.app, createdFile); |
| 620 | |
| 621 | return createdFile; |
| 622 | } catch (err) { |
| 623 | if (isMacroAbortError(err)) { |
| 624 | throw err; |
| 625 | } |
| 626 | reportError(err, `Could not create file with template at ${filePath}`); |
| 627 | return null; |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | public setLinkToCurrentFileBehavior(behavior: LinkToCurrentFileBehavior) { |
| 632 | this.formatter.setLinkToCurrentFileBehavior(behavior); |
nothing calls this directly
no test coverage detected