tera icon indicating copy to clipboard operation
tera copied to clipboard

builtin tests with if or not do not work : Failed to render '__tera_one_off'

Open uthng opened this issue 3 years ago • 4 comments

Hi,

I am using Tera in my application. It works well but I constates that builtin tests such as defined, object, string, etc. do not work. I tried to use them as below:

{{ result['subuser-create']['toto'] | defined }}

or

{% if result['subuser-create']['toto'] is defined %}...

I use render_str to render templates.

Can you tell me if there is any settings to do ?

Thanks for your helps.

NT

uthng avatar Mar 28 '22 21:03 uthng

It looks like you're using Tera::one_off from the template name, how are you using render_str then?

Keats avatar Mar 29 '22 10:03 Keats

I rendered this string:

"{\n \"subuser\": \"{{ context.data.tenant_id }}\",\n \"event\": \"SUBUSER_CREATED\",\n \"payload\": {},\n \"status\": 0,\n \"error\": {% if result['subuser-create']['output']['content']['errors'] is defined %}{{ result['subuser-create']['output']['content']['errors'] | json_encode() | safe }}{% else %}N/A{% endif %}\n}\n"

using : tera.render_str(s.as_str(), &context) for example.

uthng avatar Mar 29 '22 12:03 uthng

Can you past the whole Tera instantiation and the error you get?

Keats avatar Mar 29 '22 12:03 Keats

It looks like you're using Tera::one_off from the template name, how are you using render_str then?

Both render_str and one_off uses the same default name.

nulltier avatar May 22 '22 20:05 nulltier