Skip to content

Conversation

kenji-miyake-ai
Copy link
Contributor

It's helpful if we can use trim_blocks and lstrip_blocks rendering options.

Explaining with a sample in https://ttl255.com/jinja2-tutorial-part-3-whitespace-control/.

sample.jinja2:

{% for iname, idata in interfaces.items() %}
interface {{ iname }}
 description {{ idata.description }}
  {% if idata.ipv4_address is defined %}
 ip address {{ idata.ipv4_address }}
  {% endif %}
{% endfor %}

input.yaml:

interfaces:
  Ethernet1:
    description: capture-port
  Ethernet2:
    description: leaf01-eth51
    ipv4_address: 10.50.0.0/31
  • No option
$ jinja2 sample.jinja2 input.yaml

interface Ethernet1
 description capture-port


interface Ethernet2
 description leaf01-eth51

 ip address 10.50.0.0/31


  • Only --trim-blocks
jinja2 sample.jinja2 input.yaml --trim-blocks
interface Ethernet1
 description capture-port
  interface Ethernet2
 description leaf01-eth51
   ip address 10.50.0.0/31
  • Both --trim-blocks and --lstrip-blocks
$ jinja2 sample.jinja2 input.yaml --trim-blocks --lstrip-blocks
interface Ethernet1
 description capture-port
interface Ethernet2
 description leaf01-eth51
 ip address 10.50.0.0/31

@kenji-miyake-ai
Copy link
Contributor Author

@mattrobenolt Could you also review this? 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant