Reference a file relative #1363
-
Hello, is the a way to reference/read a file relative to the current template file? I need this in order to load a file with variables that are specific to the templates of this subdirectory. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
@ptr1120 is there a reason you need to use If you do need to use |
Beta Was this translation helpful? Give feedback.
-
@hairyhenderson : first of all thank for this great project and for your answer. My use case ist that I have a lot of yml configuration files for several tenants. Imagine the following simplified file/directory structure
The .env files contain critical variables like the tenantId that is used in the other yml files. My problem is that I want to ensure, when referencing a tenantId in a yml, that it is the id from the .env file in this subdirectory tree. Using an absolute path would introduce the risk of failures due to copy and paste. |
Beta Was this translation helpful? Give feedback.
-
thank you and sorry I wrote it from my mobile phone. |
Beta Was this translation helpful? Give feedback.
-
I realized that this probably belongs in the |
Beta Was this translation helpful? Give feedback.
-
Looks very promising, nice that you also provide both functions |
Beta Was this translation helpful? Give feedback.
@ptr1120 is there a reason you need to use
file.Read
, rather than including the file as a datasource?.env
type files are natively supported by gomplate...If you do need to use
file.Read
though, the path is relative to your current working directory (i.e. whatever thepwd
command returns). I've thought in the past of some sort ofself
function, which could return the template's path, or something similar, but I'm not certain how necessary it really is... Every use-case I've run into for it turned out to be a symptom of me trying to do something in an awkward and inelegant way 😉