user5368457
user5368457

Reputation: 21

Parsing a token with hyphen in Jinja

I have a token which has hyphen in it and I am trying to read it in jinja, Here is the sample code:

{
  [
    {
        {% for curPool in data.pool %}                  
            "name": "{{curPool.name}}",
            "my-org":"{{curPool.my-org}}"           
        {% endfor %}
    }
  ]
}

The variable curPool has two fields: name and my-org ( i have no choice of defining these tokens)

When I run this code, I get an error:

Can't render, error: 'unsupported operand type(s) for -: 'Undefined' and 'Undefined''

It seems to me that it does not know how to parse the hyphen in the token name. I have tried to escape it with '\', ''', and a '%'. But nothing works. Would appreciate your help

Thanks

Upvotes: 2

Views: 3729

Answers (1)

Ryon Sherman
Ryon Sherman

Reputation: 1583

dict.get() can be used:

"my-org":"{{curPool.get('my-org')}}"

Upvotes: 3

Related Questions