vscode-folder-templates icon indicating copy to clipboard operation
vscode-folder-templates copied to clipboard

Add folder and template paths variables

Open tmura-ido opened this issue 3 years ago • 5 comments

It would be nice if there was a variable to add inside the template that contains the project template output path like imports.

example:

template_name:
  file.js
  inside_folder:
    datasource.js

if I select the template path inside the project realtive path src/, inside the datasource.js would be two options to relative paths to the project

  1. [FTTemplatePath] template output root path -> src/template_name (or src)
  2. [FTRelativePath] template output file path -> src/template_name/inside_folder

so inside the datasource.js file I could use the relative path it has to import the file.js

import {foo, bar} from '[FTTemplatePath]/file.js';

tmura-ido avatar Feb 28 '22 08:02 tmura-ido

Hey, sorry for taking a while to respond.

I think this is kind of tricky to implement.

for [FTTemplatePath] these things come to mind

  • src/<template_name> is an "absolute" notation that can resolve to very different things depending on the project configuration IIRC. This would be problematic.
  • resolving the path relative to the current file should be possible.
  • This would result in you not getting src/template_name but ./ or ././ etc. depending on how deep you currently are in the template folder hierarchy

[FTRelativePath] doesn't make sense to me to be honest. It would be the same as a simple ./ or am I missing something here? Can you maybe give another example so I can understand better?

Huuums avatar Mar 07 '22 10:03 Huuums

That would be nice to be implemented. In the file, we can have a path to file ../../../filename.ts, however, you can create it in a different folder in the solution and the path won't work. You need to change it manually to correct one, e.g. ../../filename.ts.

stanimirt-broadcom avatar Apr 08 '22 12:04 stanimirt-broadcom

This would be useful. For example to define golang package name on each file using the name of the parent folder

project
  |- foo
  |      |- bar.go
// bar.go
package foo

...

lucas-labs avatar Jul 13 '23 02:07 lucas-labs

I'm not sure if this is the same thing or not, but I certainly think it would be useful to have a variable such as FTDirectory which points to the directory in which you are creating your template folder.

Similar to how VSCode snippets offers a TM_DIRECTORY variable.

This would allow me to include imports in my template files:

// Template folder
My Custom Template: // this is the template directory in .fttemplates
  index.ts
  other.ts
// in index.ts
import other from "<FTDirectory>/<FTName>/other";

Additional context: This would be useful in my case since we don't use relative imports (./) in our repo—paths are all relative to the project root.

nickiepucel avatar Feb 12 '24 20:02 nickiepucel