Templater rename using variables lifted from Zotero reference

I’m trying to use templater to create some data and rename a file that pulls information from a Zotero reference.

I’ve tried this:

   let title = "{{title}}";
   let year  = "{{date | format('YYYY')}}";
   let filename = `${year} ${title}`;
   await tp.file.rename(`${filename}`);

And numerous permutations of it. In the current form, the output (the note I create from the template):

   let title = "Reassessment of SST4 Somatostatin Receptor Expression Using SST4-eGFP Knockin Mice and the Novel Rabbit Monoclonal Anti-Human SST4 Antibody 7H49L61";
   let year  = "2021";
   let filename = `${year} ${title}`;
   await tp.file.rename(`${filename}`);

So it populates the the title and year, but nothing after that.

I can’t really figure out why that doesn’t work, since the below template I made for creating notes from template woks fine, and also renames the file.

Template that works here
   let title = tp.file.title;
   if (title.startsWith('Untitled')) {
	  await tp.file.move(`/Notes/Meeting notes/Untitled__`)
      participants = await tp.system.prompt('Participants');
      let userInputDate = await tp.system.prompt('Date');
      let date;
      if (!userInputDate || ["today", "0", "now"].includes(userInputDate.toLowerCase())) {
          date = tp.date.now('YYYYMMDD');
      } else if (["1", "+1", "tomorrow"].includes(userInputDate.toLowerCase())) {
          date = tp.date.tomorrow('YYYYMMDD');
      } else if (["-1", "yesterday"].includes(userInputDate.toLowerCase())) {
          date = tp.date.yesterday('YYYYMMDD');
      } else if (/^\d{4}-\d{2}-\d{2}$/.test(userInputDate)) {
          date = userInputDate;
      } else {
          date = tp.date.now('YYYYMMDD'); // Default to current date if input doesn't match any condition
      title = `${date} Meeting with ${participants}`
      await tp.file.rename(`${title}`);

Things I have tried

I’ve of course searched, and there are many Templater questions, also about rename, but none I could find that seem to address this. Although, since I don’t know what the problem is, I might be searching for the wrong terms…

1 Like

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