I’m trying to use a variable I’ve gotten from tp.system.suggester as part of a file move operation later on in my template.
But this throws an error (not sure what it says because I don’t know where to find the error console). Is there some way to refer to that tag/suggester variable in order for this move operation to work?
Looking more closely, I guess the tp.file.tags returns an array of string. I’ll have to figure out how to extract the first tag…
Well, back to the original “Can I use the suggester variable somewhere else”?
I have been trying to explore something similar today. Here is one way to do use the returned value
<%*
// Get the type of source
const source_types = ["youtube","webpage","kindle"]
let input_source_type = await tp.system.suggester(source_types, source_types, true, "What is source type?");
let tags = "tags: [note/reference/" + input_source_type + "]"
_%>
Thanks, that helped with the file move, but now I’m not sure how the “tag” area gets populated…
I tried this:
<%*
const departments = ["anim", "comp", "gen", "layout", "fx", "crdev" , "paint"]
let input_dept = await tp.system.suggester(departments, departments, true, "What department do they work in?")
let tags = "---\ntags: " + input_dept + "\n---"
await tp.file.move("STC/Crew/" + input_dept + "/" + tp.file.title) _%>
although that looks like it’s just setting the variable for tags and not actually including it anywhere, so then I tried:
---
tags:
---
<%*
const departments = ["anim", "comp", "gen", "layout", "fx", "crdev" , "paint"]
let input_dept = await tp.system.suggester(departments, departments, true, "What department do they work in?")
tp.frontmatter.tags = input_dept
await tp.file.move("STC/Crew/" + input_dept + "/" + tp.file.title) _%>
But that didn’t work either…
holroy
January 22, 2023, 9:14pm
5
See the following for inspiration as to how to solve your issue:
Here is what I would do, and this is using JavaScript Execution Commands , so please take care when running any script like this.
This needs to be placed at the top of your file. The underscores are for whitespace control , you can modify them to fit your purpose. (I might have got the order of the _ and * wrong, try swapping if this doesn’t work)
<%_*
let title = tp.file.title;
var keyTerm = '';
if (title.startsWith("Term ")) {
// You can use a more complicated extraction system like regex…
2 Likes
Once again, thank you holroy! That is exactly what I was looking for!
system
Closed
January 29, 2023, 9:34pm
7
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.