在 Tyk 仪表板模板文件中显示环境变量的值是否可能?

huangapple go评论74阅读模式
英文:

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 Tyk's top_nav.tmp template file, I'm now trying to display the value of my environment variable MY_VAR.
I want to 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.

英文:

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

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

version: &#39;3.6&#39;
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:

&lt;p&gt;
{{ .Env.MY_VAR }}
&lt;/p&gt;

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.

答案1

得分: 1

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

&lt;p&gt;
{{ env &quot;MY_VAR&quot; }}
&lt;/p&gt;
英文:

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

&lt;p&gt;
{{ env &quot;MY_VAR&quot; }}
&lt;/p&gt;

huangapple
  • 本文由 发表于 2023年5月24日 18:00:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322289.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定