{%- if filetype_loop == 0 %}Instance,BGP ID,State,VRF,Router ID,Cluster ID,Confederation ID,Neighbor,Version,Hold Time,Keep Alive Interval,Local AS,Remote AS,Total Recieved Messages,Total Sent Messages,Connect Last Reset,Reset Reason
{%-     for instance in to_parse_bgp %}
{%-         for vrf in to_parse_bgp[instance].vrf %}
{%-             for neighbor in to_parse_bgp[instance].vrf[vrf].neighbor %}
{{ instance }},{{ to_parse_bgp[instance].bgp_id }},{{ to_parse_bgp[instance].protocol_state }},{{ vrf }},{{ to_parse_bgp[instance].vrf[vrf].router_id }},{{ to_parse_bgp[instance].vrf[vrf].cluster_id }},{{ to_parse_bgp[instance].vrf[vrf].confederation_identifier }},{{ neighbor }},{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_version }},{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].holdtime }},{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].keepalive_interval }},{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].local_as_as_no }},{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].remote_as }},{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_neighbor_counters.messages.received.total }},{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_neighbor_counters.messages.sent.total }},{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_session_transport.connection.last_reset }},{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_session_transport.connection.reset_reason }}
{%-             endfor %}
{%-         endfor %}
{%-     endfor %}
{%- else %}
{%-     if filetype_loop == 1 %}
# Learn BGP
| Instance | BGP ID | State | VRF | Router ID | Cluster ID | Confederation ID | Neighbor | Version | Hold Time | Keep Alive Interval | Local AS | Remote AS | Total Recieved Messages | Total Sent Messages | Connect Last Reset | Reset Reason |
| -------- | ------ | ----- | --- | --------- | ---------- | ---------------- | -------- | ------- | --------- | ------------------- | -------- | --------- | ----------------------- | ------------------- | ------------------ | ------------ |
{%-         for instance in to_parse_bgp %}
{%-             for vrf in to_parse_bgp[instance].vrf %}
{%-                 for neighbor in to_parse_bgp[instance].vrf[vrf].neighbor %}
| {{ instance }} | {{ to_parse_bgp[instance].bgp_id }} | {{ to_parse_bgp[instance].protocol_state }} | {{ vrf }} | {{ to_parse_bgp[instance].vrf[vrf].router_id }} | {{ to_parse_bgp[instance].vrf[vrf].cluster_id }} | {{ to_parse_bgp[instance].vrf[vrf].confederation_identifier }} | {{ neighbor }} | {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_version }} | {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].holdtime }} | {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].keepalive_interval }} | {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].local_as_as_no }} | {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].remote_as }} | {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_neighbor_counters.messages.received.total }} | {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_neighbor_counters.messages.sent.total }} | {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_session_transport.connection.last_reset }} | {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_session_transport.connection.reset_reason }} |
{%-                 endfor %}
{%-             endfor %}
{%-         endfor %}
{%-     else %}
{%-         if filetype_loop == 2 %}
<html><body>
<h1>Learn BGP</h1>
<table>
<thead>
  <tr>
    <th>Instance</th>
    <th>BGP ID</th>
    <th>State</th>
    <th>VRF</th>
    <th>Router ID</th>
    <th>Cluster ID</th>
    <th>Confederation ID</th>
    <th>Neighbor</th>
    <th>Version</th>
    <th>Hold Time</th>
    <th>Keep Alive Interval</th>
    <th>Local AS</th>
    <th>Remote AS</th>
    <th>Total Recieved Messages</th>
    <th>Total Sent Messages</th>
    <th>Connect Last Reset</th>
    <th>Reset Reason</th>
  </tr>
  </thead>
  <tbody>
{%-             for instance in to_parse_bgp %}
{%-                 for vrf in to_parse_bgp[instance].vrf %}
{%-                     for neighbor in to_parse_bgp[instance].vrf[vrf].neighbor %}
<tr>
    <td>{{ instance }}</td>
    <td>{{ to_parse_bgp[instance].bgp_id }}</td>
    <td>{{ to_parse_bgp[instance].protocol_state }}</td>
    <td>{{ vrf }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].router_id }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].cluster_id }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].confederation_identifier }}</td>
    <td>{{ neighbor }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_version }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].holdtime }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].keepalive_interval }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].local_as_as_no }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].remote_as }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_neighbor_counters.messages.received.total }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_neighbor_counters.messages.sent.total }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_session_transport.connection.last_reset }}</td>
    <td>{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_session_transport.connection.reset_reason }}</td>
  </tr>
{%-                     endfor %}
{%-                 endfor %}
{%-             endfor %}
  </tbody>  
</table>
</body></html>
{%-         else %}
# Learn BGP
{%-             for instance in to_parse_bgp %}
## Instance: {{ instance }}
### BGP ID: {{ to_parse_bgp[instance].bgp_id }}
### Protocol State: {{ to_parse_bgp[instance].protocol_state }}
### VRF
{%-                 for vrf in to_parse_bgp[instance].vrf %}
#### {{ vrf }}
##### ID
###### Router: {{ to_parse_bgp[instance].vrf[vrf].router_id }}
###### Cluster: {{ to_parse_bgp[instance].vrf[vrf].cluster_id }}
###### Confederation: {{ to_parse_bgp[instance].vrf[vrf].confederation_identifier }}
##### Neighbor
{%-                     for neighbor in to_parse_bgp[instance].vrf[vrf].neighbor %}
###### {{ neighbor }}
###### BGP Version: {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_version }}
###### Holdtime: {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].holdtime }}
###### Keepalive Interval: {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].keepalive_interval }}
###### Local AS Number: {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].local_as_as_no }}
###### Remote AS: {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].remote_as }}
###### Total Messages Received: {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_neighbor_counters.messages.received.total }}
###### Total Messages Sent: {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_neighbor_counters.messages.sent.total }}
###### Last Reset: {{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_session_transport.connection.last_reset }}
###### Reset Reason{{ to_parse_bgp[instance].vrf[vrf].neighbor[neighbor].bgp_session_transport.connection.reset_reason }}
{%-                     endfor %}
{%-                 endfor %}
{%-             endfor %}
{%-         endif %}
{%-     endif %}
{%- endif %}