from comments in #346 :
Also, we should add documentation :) (also mentioned in #355)
This all looks great @riccardoferretti. I'd also add some tests would be good to have
I'm happy to look at this next week?
sound good @ingalless!
Marsop in discord suggested:
This should probably kick off a broader discussion of what "dynamic" variables we should support.
"date (_or datetime_) of creation" would be a good candidate for dynamic variable (similar as how "daily" notes receive a name based on when they have been created.
@marsop it would be worth checking if the above is available in the list of snippet variables:
https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables
Tested and working!
Example template:
# ${TM_FILENAME_BASE}
- Date: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}
when creating file with name "test5.md" generates..
# test5
- Date: 2020-11-20
Would be amazing to have also a command like "Insert from template" to insert at the cursor's position in your current document the content stored in a template.
This, plus what you are discussing about variables, I think would be a very useful feature. What do you think?
@danielarmengolaltayo we could do something like that, sure
But then I wonder: are we straying back into the functionality of snippets (which has the benefit of Microsoft maintaining it)?
@riccardoferretti any thoughts?
@ingalless I see what you mean, I personally don't see an issue with having and "Insert from template" command.
The main reasons are:
./foam/templates/ dir, instead of snippets, which IMO is a bit nicer)A possible drawback I see is for the templates/ directory to become a kitchen sink, but then again who am I to judge.. if someone prefers it that way, we are not taking options away from them.
TLDR;
I am open to it, I don't feel strongly about it, and happy to have a conversation on the topic if people disagree
@ingalless I agree with you about how templates are overlapping with snippets' functionality. Never created a snippet before and now I see how it's barely the same.
My proposal was made before playing around with snippets a bit and it was made as a reaction to the new template's feature. I was just imagining a use case out from what the nature of the feature suggested to me.
I also agree with @riccardoferretti regarding the source of truth point, but I don't know if it is worth the cost of developing and maintaining a template's feature (not just insert but also create new note), understanding that the same is completely achievable through snippets.
The only reason that comes into my mind at the moment, to append to @riccardoferretti 's list is about UX. For non-tech savvy users, templates seems a better way to go IMO, if you are not thinking of variables for now, just plain text.
Ok, more thoughts about this.
I have the file containing the snippets' configuration inside the .vscode folder inside my foam project. For me, this is equivalent to .foam/templates and a file per template, regarding the source of truth point.
I can open the snippets' file easily and fast through "search by files name" (cmd+P in mac) and typing "templates" (if I name the snippets' file something like "templates.code-snippets"), which is the same experience as retrieving a template file.
In conclusion, if there are no more functionalities in mind for templates, IMO we can have the same results with proper documentation explaining how to create your templates using snippets. What do you think @ingalless @riccardoferretti ?
@danielarmengolaltayo I agree on @riccardoferretti's point that it doesn't hurt for us to add a "insert at cursor" command. You're right, the "templates" mindset works better for non-technical users than snippets do (they're a bit awkward to work with). It's good we support non-technical users as it's part of Foam's core values.
@ingalless And also, sometimes it is nice to have multiple ways to achieve the same result so that each person can decide what works best for him/her. My last concern was more about the effort required to "replicate" and maintain a functionality like this, but if you feel like it doesn't hurt, I don't see why not ;)
I think it's a nice to have, and I agree that as a first quick iteration documenting the "workaround" can be just as good.
I am happy to defer to @ingalless to make the call as to whether to add it now or later based on his cost/benefit analysis.
Most helpful comment
@ingalless I see what you mean, I personally don't see an issue with having and "Insert from template" command.
The main reasons are:
./foam/templates/dir, instead of snippets, which IMO is a bit nicer)A possible drawback I see is for the
templates/directory to become a kitchen sink, but then again who am I to judge.. if someone prefers it that way, we are not taking options away from them.TLDR;
I am open to it, I don't feel strongly about it, and happy to have a conversation on the topic if people disagree