Templater deletes parts of templater script

Hi there,

my templater scripts has two parts (thanks to the explanations of @gino_m in that thread):

  1. adding / updating properties
  2. Moving note to specific folder
  3. adding a dataview

If I use this templater script I see the following:

  • No error message
  • the dataview source code
  • After (assumable) 0,5 seconds the dataview code gets deleted and the properties are added

My question is:
Why will the dataview be deleted?

… what is funny:
If I use this script a second time, on that note, that - now - already has the right properties, the dataview will be added…

Templater script for library notes

<%*
// Check if the 'value' tag exists before adding it
setTimeout(() => {
  app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => {
	let key = "aliases"
	let value = ""
	if (!frontmatter[key] || !frontmatter[key].includes(value)) {
      const prop_Array = Array.isArray(frontmatter[key]) ? frontmatter[key] : [];
      if (!prop_Array.includes(value)) {
        prop_Array.push(value);
        frontmatter[key] = prop_Array;
      }
    }
	key = "created"
	value = tp.date.now()
	if (!frontmatter[key] || !frontmatter[key].includes(value)) {
	  const prop_Array = Array.isArray(frontmatter[key]) ? frontmatter[key] : [];
	  if (!prop_Array.includes(value)) {
		prop_Array.push(value);
		frontmatter[key] = prop_Array;
	  }
	}
	key = "tags"
	value = "note/library"
	if (!frontmatter[key] || !frontmatter[key].includes(value)) {
      const prop_Array = Array.isArray(frontmatter[key]) ? frontmatter[key] : [];
      if (!prop_Array.includes(value)) {
        prop_Array.push(value);
        frontmatter[key] = prop_Array;
      }
    }
	delete frontmatter['Unwanted property']
  });
}, 550); // Timeout to allow preceding clipboard operations to complete
_%>
<% await tp.file.move("Atlas/Maps/Library/" + tp.file.title) %>
```dataview
Table tags, file.folder
From #note or "Atlas"
Where contains(Library, [[]])
```

Thanks in advance,
kind regards,

Silias

I’m not seeing this.
Try increasing the timeout value maybe.

(Also, as a side note, the word ‘clipboard’ has no meaning here in your use case or comment line.)

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