Skip to content

Commit 4e48ff1

Browse files
committed
Merge branch 'main' of https://github.com/NotePlan/plugins
2 parents ef3dff0 + d8939cd commit 4e48ff1

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

np.Templating/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
See Plugin [README](https://github.com/NotePlan/plugins/blob/main/np.Templating/README.md) for details on available commands and use case.
66

7+
## [1.11.4] 2025-03-07 @dwertheimer
8+
9+
- Fix: templateFileByTitleEx (templateRunner) was failing to process EJS tags in the frontmatter of receiving template (thx @jgclark)
10+
711
## [1.11.3] 2025-03-06 @dwertheimer
812

913
- Fix: Improve Template error message (put it in a code block)

np.Templating/lib/NPTemplating.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { debug, helpInfo } from './helpers'
1313

1414
import globals from './globals'
1515
import { chooseOption } from '@helpers/userInput'
16-
import { clo, log, logError, logDebug, logWarn, timer } from '@helpers/dev'
16+
import { clo, log, logError, logDebug, logWarn, timer, clof } from '@helpers/dev'
1717
import { datePicker, askDateInterval, chooseFolder } from '@helpers/userInput'
1818

1919
/*eslint-disable */
@@ -657,7 +657,7 @@ export default class NPTemplating {
657657
// we don't have a template yet, so we need to find one using title
658658
logDebug(pluginJson, `NPTemplating.getTemplate: Searching for template by title without path "${originalFilename}"`)
659659
let templates = await DataStore.projectNoteByTitle(originalFilename, true, false)
660-
clo(templates, `NPTemplating.getTemplate: found templates`)
660+
clof(templates, `NPTemplating.getTemplate: found ${templates?.length || 0} templates`, ['title', 'filename'], true)
661661
if (templates && templates.length > 1) {
662662
logWarn(pluginJson, `NPTemplating.getTemplate: Multiple templates found for "${templateFilename || ''}"`)
663663
let templatesSecondary = []

np.Templating/plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"noteplan.minAppVersion": "3.9.10",
44
"plugin.id": "np.Templating",
55
"plugin.name": "📒 Templating",
6-
"plugin.version": "1.11.3",
7-
"plugin.lastUpdateInfo": "1.11.3: Minor improvements and bug fixes",
6+
"plugin.version": "1.11.4",
7+
"plugin.lastUpdateInfo": "1.11.4: Minor improvements and bug fixes",
88
"plugin.description": "Templating Plugin for NotePlan",
99
"plugin.author": "Mike Erickson (@codedungeon)",
1010
"plugin.dependencies": [],

np.Templating/src/NPEditor.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import FrontmatterModule from '@templatingModules/FrontmatterModule'
2020

2121
import pluginJson from '../plugin.json'
2222
import { hyphenatedDate } from '@helpers/dateTime'
23-
import { selectFirstNonTitleLineInEditor } from '@helpers/NPnote'
23+
import { selectFirstNonTitleLineInEditor, getNoteFromIdentifier } from '@helpers/NPnote'
2424
import { findEndOfActivePartOfNote } from '@helpers/paragraph'
2525
import { 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

Comments
 (0)