Search code examples
go-templatestyk

Is it possible to display the value of an environment variable in a Tyk Dashboard template file?


I'm trying to reference an environment variable in Tyk Dashboard.

I set up a docker-compose.yaml file containing environment variables:

version: '3.6'
services:
  tyk-portal:
    image: tykio/portal:v1.3.0
    command: --bootstrap
    ports:
      - 3001:3001
    environment:
      - ...
      - MY_VAR=someValue123

When I run docker-compose up, I can navigate to the Tyk dashboard on localhost:3001.

Inside Tyks top_nav.tmp template file I'm now trying to display the value of my environment variable MY_VAR. I want use something like this:

<p>
{{ .Env.MY_VAR }}
</p>

However, nothing is displayed. I cannot find a concrete example in the docs and I'm starting to wonder if referencing an environment variable inside a Tyk template file is at all possible.


Solution

  • Tyk bundles the Sprig Library (v3) which has the env function. Use it like this:

    <p>
    {{ env "MY_VAR" }}
    </p>