I'm trying to write a template using ninja. But I can't display the right indentation! I tried a lot of stuffs but I couldn't get the expected result. I have a dictionary like this:
videoNode = {'type': "VideoLoader",
'config': {'type': "url",
'source': "blabla",
'frameBufferSize': 50,
}
}
I would like to display something like that
queueVideo1:
type: VideoLoader
config:
source: blabla
type: url
frameBufferSize: 50
but all I can get is:
queueVideo1:
type: VideoLoader
config:
source: blabla
type: url
frameBufferSize: 50
Here is my file:
{%- for key, value in videoNodes.iteritems() recursive -%}
{%+ if value is mapping -%}
{{ key }}:
{{ loop(value.iteritems()) }}
{%- else -%}
{{ key }}: {{value}}
{% endif %}
{%- endfor -%}
You must try using indent function and asign a value depends of your level of indentation:
{{ key|indent(2, true) }}
You can see the documentation here
I found it helpful to use multiple indent filters to keep my yaml file indentation clear. It was getting a little confusing otherwise:
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ name }}
namespace: {{ namespace }}
data:
{% filter indent(2) %}
customResourceDefinitions: |-
{% filter indent(2) %}
{%- for crd in crds -%}
- {{ crd.content|indent(2) }}
{%- endfor -%}
{% endfilter %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With