How do I connect .env file to config.yml?

Viewed 660

I'm currently building a Shopify store and would like to use env variables in Themekit's config.yml file. What I'm confused about is how to connect the .env file to the yml file, since I don't think you can just require dotenv. I have my .env file, and the code below in the config.yml. Thanks!

password: ${DEV_PASSWD}
theme_id: ${DEV_THEMEID}
store: ${DEV_SHOP}
1 Answers

You can't include .env file inside a YAML one. However, you can interpolate variables into your config.yml file using the ${} notation.

To help you interpolate variables, there are special files that can be used to automatically to load environment variables for Theme Kit. The following table lists the file paths for each operating system:

  • macOs: ${HOME}/Library/Application Support/Shopify/Themekit/variables
  • Linux/BSD: ${XDG_CONFIG_HOME}/Shopify/Themekit/variables
  • Windows: %APPDATA%\Shopify\Themekit\variables

Even more, you can use the --vars flag in any command to provide a path to a file for loading variables. The variables file has the same format as most .env type files. But note, the .env file is not interpolated by YAML itself and it cannot be connected using standard YAML include directives. All magic is provided exclusively by shopify and its --vars flag.

Related