{%- if filetype_loop == 0 %}VLAN,Address Family,Version,Group,Active Router,HSRP State,Preempt,IPv4 Address,Virtual IP Learn,Priority,Session Name,Standby IP Address,Standby Router,Hello Timer,Hold Timer,Virtual MAC,Use BIA
{%-     for vlan in to_parse_hsrp %}
{%-         for address_family in to_parse_hsrp[vlan].address_family %}
{%-             for version in to_parse_hsrp[vlan].address_family[address_family].version %}
{%-                 for group in to_parse_hsrp[vlan].address_family[address_family].version[version].groups %}
{{ vlan }},{{ address_family }},{{ version }},{{ group }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].active_router }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].hsrp_router_state }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].preempt }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].primary_ipv4_address.address }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].primary_ipv4_address.virtual_ip_learn }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].priority }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].session_name }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].standby_ip_address }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].standby_router }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].timers.hello_sec }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].timers.hold_sec }},{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].virtual_mac_address }},{{ to_parse_hsrp[vlan].use_bia }}
{%-                 endfor %}
{%-             endfor %}
{%-         endfor %}
{%-     endfor %}
{%- else %}
{%-     if filetype_loop == 1 %}
# Learn HSRP
| VLAN | Address Family | Version | Group | Active Router | HSRP State | Preempt | IPv4 Address | Virtual IP Learn | Priority | Session Name | Standby IP Address | Standby Router | Hello Timer | Hold Timer | Virtual MAC | Use BIA |
| ---- | -------------- | ------- | ----- | ------------- | ---------- | ------- | ------------ | ---------------- | -------- | ------------ | ------------------ | -------------- | ----------- | ---------- | ----------- | ------- |
{%-         for vlan in to_parse_hsrp %}
{%-             for address_family in to_parse_hsrp[vlan].address_family %}
{%-                 for version in to_parse_hsrp[vlan].address_family[address_family].version %}
{%-                     for group in to_parse_hsrp[vlan].address_family[address_family].version[version].groups %}
| {{ vlan }} | {{ address_family }} | {{ version }} | {{ group }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].active_router }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].hsrp_router_state }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].preempt }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].primary_ipv4_address.address }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].primary_ipv4_address.virtual_ip_learn }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].priority }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].session_name }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].standby_ip_address }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].standby_router }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].timers.hello_sec }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].timers.hold_sec }} | {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].virtual_mac_address }} | {{ to_parse_hsrp[vlan].use_bia }} |
{%-                     endfor %}
{%-                 endfor %}
{%-             endfor %}
{%-         endfor %}
{%-     else %}
{%-         if filetype_loop == 2 %}
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.0/js/dataTables.buttons.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.0/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.0/js/buttons.print.min.js"></script>
    <script src="https://cdn.datatables.net/colreorder/1.5.4/js/dataTables.colReorder.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.0/js/buttons.colVis.min.js"></script>
    <script src="https://cdn.datatables.net/keytable/2.6.4/js/dataTables.keyTable.min.js"></script>
    <script src="https://cdn.datatables.net/select/1.3.3/js/dataTables.select.min.js"></script>
    <script src="https://cdn.datatables.net/fixedheader/3.1.9/js/dataTables.fixedHeader.min.js"></script>
    <link rel="stylesheet" href="https://cdn.datatables.net/fixedheader/3.1.9/css/fixedHeader.dataTables.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/select/1.3.3/css/select.dataTables.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/keytable/2.6.4/css/keyTable.dataTables.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.min.css">
</head>
<body>
<h1>Learn HSRP</h1>
<table id = "hsrp">
  <thead>
  <tr>
    <th>VLAN</th>
    <th>Address Family</th>
    <th>Version</th>
    <th>Group</th>
    <th>Active Router</th>
    <th>HSRP State</th>
    <th>Preempt</th>
    <th>IPv4 Address</th>
    <th>Virtual IP Learn</th>
    <th>Priority</th>
    <th>Session Name</th>
    <th>Standby IP Address</th>
    <th>Standby Router</th>
    <th>Hello Timer</th>
    <th>Hold Timer</th>
    <th>Virtual MAC</th>
    <th>Use BIA</th>
  </tr>
  </thead>
  <tbody>
{%-             for vlan in to_parse_hsrp %}
{%-                 for address_family in to_parse_hsrp[vlan].address_family %}
{%-                     for version in to_parse_hsrp[vlan].address_family[address_family].version %}
{%-                         for group in to_parse_hsrp[vlan].address_family[address_family].version[version].groups %}
<tr>
    <td>{{ vlan }}</td>
    <td>{{ address_family }}</td>
    <td>{{ version }}</td>
    <td>{{ group }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].active_router }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].hsrp_router_state }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].preempt }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].primary_ipv4_address.address }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].primary_ipv4_address.virtual_ip_learn }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].priority }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].session_name }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].standby_ip_address }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].standby_router }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].timers.hello_sec }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].timers.hold_sec }}</td>
    <td>{{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].virtual_mac_address }}</td>
    <td>{{ to_parse_hsrp[vlan].use_bia }}</td>
  </tr>
{%-                         endfor %}
{%-                     endfor %}
{%-                 endfor %}
{%-             endfor %}
  </tbody>  
</table>
<script type = "text/javascript">
  $(document).ready(function(){
    $('#hsrp thead tr')
    .clone(true)
    .addClass('filters')
    .appendTo('#hsrp thead');

    var table = $('#hsrp').DataTable({
        keys: true,
        dom: 'Bfrtip',
        lengthMenu: [
            [ 10, 25, 50, -1 ],
            [ '10 rows', '25 rows', '50 rows', 'Show all' ]
        ],
        buttons: [
        'pageLength','colvis','copy', 'csv', 'excel', 'pdf', 'print'
        ],
        colReorder: true,
        select: true,            
        orderCellsTop: true,
        fixedHeader: true,
        initComplete: function () {
        var api = this.api();

        // For each column
        api
            .columns()
            .eq(0)
            .each(function (colIdx) {
                // Set the header cell to contain the input element
                var cell = $('.filters th').eq(
                    $(api.column(colIdx).header()).index()
                );
                var title = $(cell).text();
                $(cell).html('<input type="text" placeholder="' + title + '" />');

                // On every keypress in this input
                $(
                    'input',
                    $('.filters th').eq($(api.column(colIdx).header()).index())
                )
                    .off('keyup change')
                    .on('keyup change', function (e) {
                        e.stopPropagation();

                        // Get the search value
                        $(this).attr('title', $(this).val());
                        var regexr = '({search})'; //$(this).parents('th').find('select').val();

                        var cursorPosition = this.selectionStart;
                        // Search the column for that value
                        api
                            .column(colIdx)
                            .search(
                                this.value != ''
                                    ? regexr.replace('{search}', '(((' + this.value + ')))')
                                    : '',
                                this.value != '',
                                this.value == ''
                            )
                            .draw();

                        $(this)
                            .focus()[0]
                            .setSelectionRange(cursorPosition, cursorPosition);
                    });
            });
    },
});
});        
</script>
</body></html>
{%-         else %}
# Learn HSRP
{%-             for vlan in to_parse_hsrp %}
{%-                 for address_family in to_parse_hsrp[vlan].address_family %}
## VLAN: {{ vlan }} - {{ address_family }}
{%-                     for version in to_parse_hsrp[vlan].address_family[address_family].version %}
### Version: {{ version }}
{%-                         for group in to_parse_hsrp[vlan].address_family[address_family].version[version].groups %}
#### Group: {{ group }}
##### Router
###### Active: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].active_router }}
###### State: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].hsrp_router_state }}
##### Preempt: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].preempt }}
##### IP
###### Address: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].primary_ipv4_address.address }}
###### Virtually Learn: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].primary_ipv4_address.virtual_ip_learn }}
##### Priority: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].priority }}
##### Session Name: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].session_name }}
##### Standby 
###### IP: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].standby_ip_address }}
###### Router: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].standby_router }}
##### Timers
###### Hello: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].timers.hello_sec }}
###### Hold: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].timers.hold_sec }}
##### Virtual MAC: {{ to_parse_hsrp[vlan].address_family[address_family].version[version].groups[group].virtual_mac_address }}
##### Use BIA: {{ to_parse_hsrp[vlan].use_bia }}
{%-                         endfor %}
{%-                     endfor %}
{%-                 endfor %}
{%-             endfor %}
{%-         endif %}
{%-     endif %}
{%- endif %}