@@ -20,7 +20,7 @@ import FrontmatterModule from '@templatingModules/FrontmatterModule'
2020
2121import pluginJson from '../plugin.json'
2222import { hyphenatedDate } from '@helpers/dateTime'
23- import { selectFirstNonTitleLineInEditor } from '@helpers/NPnote'
23+ import { selectFirstNonTitleLineInEditor , getNoteFromIdentifier } from '@helpers/NPnote'
2424import { findEndOfActivePartOfNote } from '@helpers/paragraph'
2525import { chooseHeading , showMessage } from '@helpers/userInput'
2626
@@ -132,23 +132,29 @@ export async function templateFileByTitleEx(selectedTemplate?: string = '', open
132132 if ( selectedTemplate . length !== 0 ) {
133133 //TODO: call overrideSettingsWithTypedArgs() for JSON inputs from form
134134 const argObj = args && typeof args === 'string' && args . includes ( '__isJSON__' ) ? JSON . parse ( args ) : overrideSettingsWithStringArgs ( { } , args || '' )
135+ clo ( argObj , `templateFileByTitleEx argObj` )
135136
136137 // args && args.split(',').forEach((arg) => (arg.split('=').length === 2 ? (argObj[arg.split('=')[0]] = arg.split('=')[1]) : null))
137138 if ( ! selectedTemplate || selectedTemplate . length === 0 ) {
138139 await CommandBar . prompt ( 'You must supply a template title as the first argument' , helpInfo ( 'Presets' ) )
139140 }
140141 let failed = false
141142
142- const templateData = await NPTemplating . getTemplate ( selectedTemplate )
143+ // const templateData = await NPTemplating.getTemplate(selectedTemplate) -- seems to load every template in the DataStore -- I don't think it's needed
144+ const theNote = await getNoteFromIdentifier ( selectedTemplate )
145+ let templateData = ''
143146
144- if ( ! templateData ) {
147+ if ( ! theNote ) {
145148 failed = true
149+ } else {
150+ templateData = theNote . content || ''
146151 }
147152
148153 const isFrontmatter = failed ? false : new FrontmatterModule ( ) . isFrontmatterTemplate ( templateData )
154+ logDebug ( pluginJson , `templateFileByTitleEx: "${ theNote ?. title || '' } ": isFrontmatter:${ String ( isFrontmatter ) } ` )
149155 if ( ! failed && isFrontmatter ) {
150- const { frontmatterBody , frontmatterAttributes } = await NPTemplating . preRender ( templateData )
151- // clo(frontmatterAttributes, `templateFileByTitleEx frontMatterAttributes after preRender`)
156+ const { frontmatterBody , frontmatterAttributes } = await NPTemplating . preRender ( templateData , argObj )
157+ clo ( frontmatterAttributes , `templateFileByTitleEx frontMatterAttributes after preRender` )
152158 let data = { ...frontmatterAttributes , ...argObj , frontmatter : { ...frontmatterAttributes , ...argObj } }
153159 if ( data [ 'newNoteTitle' ] ) {
154160 // if form or template has a newNoteTitle field then we need to call templateNew
@@ -157,8 +163,8 @@ export async function templateFileByTitleEx(selectedTemplate?: string = '', open
157163 return
158164 }
159165 let renderedTemplate = await NPTemplating . render ( frontmatterBody , data )
160- // logDebug(pluginJson, `templateFileByTitleEx Template Render Complete renderedTemplate= "${renderedTemplate}"`)
161- // clo(frontmatterAttributes, `templateFileByTitleEx frontMatterAttributes before set`)
166+ logDebug ( pluginJson , `templateFileByTitleEx Template Render Complete renderedTemplate= "${ renderedTemplate } "` )
167+ clo ( frontmatterAttributes , `templateFileByTitleEx frontMatterAttributes before set` )
162168 // Note:getNoteTitled is going to replace openNoteTitle and writeNoteTitle
163169 // Whether it's run silently or opened in Editor is sent in the URL
164170
0 commit comments