{%- if filetype_loop == 0 %}Stack Member Number,Hardware Priority,Switch Priority,Platform ID,Role,State,MAC Address,Next Reload,Software Image,Serial Number,Port Name,Is Synch Ok,Switchport,Neighbor Port,Link OK Changes,Stack Cable Length,Stack Port Status,Link Active,Link OK
{%-   if stack.stackSwitchInfo is not none %}
{%-     for info in stack.stackSwitchInfo %}
{{ info.stackMemberNumber }},{{ info.hwPriority }},{{ info.switchPriority }},{{ info.platformId }},{{ info.role }},{{ info.state }},{{ info.macAddress }},{{ info.numNextReload }},{{ info.softwareImage }},{{ info.serialNumber }},N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
{%-     endfor %}
{%    endif %}
{%-   if stack.stackPortInfo is not none %}
{%-     for item in stack.stackPortInfo %}
N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,{{ item.name }},{{ item.isSynchOk }},{{ item.switchPort }},{{ item.neighborPort }},{{ item.nrLinkOkChanges }},{{ item.stackCableLengthInfo }},{{ item.stackPortOperStatusInfo }},{{ item.linkActive }},{{ item.linkOk }}
{%-     endfor %}
{%    endif %}
{%- else %}
{%-     if filetype_loop == 1 %}
# Stack Info
| Stack Member Number | Hardware Priority | Switch Priority | Platform ID | Role | State | MAC Address | Next Reload | Software Image | Serial Number | Port Name | Is Synch Ok | Switchport | Neighbor Port | Link OK Changes | Stack Cable Length | Stack Port Status | Link Active | Link OK |
| ------------------- | ----------------- | --------------- | ----------- | ---- | ----- | ----------- | ----------- | -------------- | ------------- | --------- | ----------- | ---------- | ------------- | --------------- | ------------------ | ----------------- | ----------- | ------- |
{%-   if stack.stackSwitchInfo is not none %}
{%-     for info in stack.stackSwitchInfo %}
| {{ info.stackMemberNumber }} | {{ info.hwPriority }} | {{ info.switchPriority }} | {{ info.platformId }} | {{ info.role }} | {{ info.state }} | {{ info.macAddress }} | {{ info.numNextReload }} | {{ info.softwareImage }} | {{ info.serialNumber }} | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A |
{%-     endfor %}
{%    endif %}
{%-   if stack.stackPortInfo is not none %}
{%-     for item in stack.stackPortInfo %}
| N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | {{ item.name }} | {{ item.isSynchOk }} | {{ item.switchPort }} | {{ item.neighborPort }} | {{ item.nrLinkOkChanges }} | {{ item.stackCableLengthInfo }} | {{ item.stackPortOperStatusInfo }} | {{ item.linkActive }} | {{ item.linkOk }} |
{%-     endfor %}
{%    endif %}
{%-     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>Device Stack Info </h1>
<table id ="stack">
  <thead>
    <tr>
      <th>Stack Member Number</th>
      <th>Hardware Priority</th>
      <th>Switch Priority</th>
      <th>Platform ID</th>
      <th>Role</th>
      <th>State</th>
      <th>MAC Address</th>
      <th>Next Reload</th>
      <th>Software Image</th>
      <th>Serial Number</th>
      <th>Port Name</th>
      <th>Is Synch Ok</th>
      <th>Switchport</th>
      <th>Neighbor Port</th>
      <th>Link OK Changes</th>
      <th>Stack Cable Length</th>
      <th>Stack Port Status</th>
      <th>Link Active</th>
      <th>Link OK</th>
    </tr>
  </thead>
  <tbody>
{%-   if stack.stackSwitchInfo is not none %}
{%-     for info in stack.stackSwitchInfo %}
<tr>
    <td>{{ info.stackMemberNumber }}</td>
    <td>{{ info.hwPriority }}</td>
    <td>{{ info.switchPriority }}</td>
    <td>{{ info.platformId }}</td>
    <td>{{ info.role }}</td>
    <td>{{ info.state }}</td>
    <td>{{ info.macAddress }}</td>
    <td>{{ info.numNextReload }}</td>
    <td>{{ info.softwareImage }}</td>
    <td>{{ info.serialNumber }}</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
  </tr>
{%-     endfor %}
{%    endif %}
{%-   if stack.stackPortInfo is not none %}
{%-     for item in stack.stackPortInfo %}
<tr>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>N/A</td>
    <td>{{ item.name }}</td>
    <td>{{ item.isSynchOk }}</td>
    <td>{{ item.switchPort }}</td>
    <td>{{ item.neighborPort }}</td>
    <td>{{ item.nrLinkOkChanges }}</td>
    <td>{{ item.stackCableLengthInfo }}</td>
    <td>{{ item.stackPortOperStatusInfo }}</td>
    <td>{{ item.linkActive }}</td>
    <td>{{ item.linkOk }}</td>
{%-     endfor %}
  </tr>
{%    endif %}
  </tbody>
</table>
<script type = "text/javascript">
  $(document).ready(function(){
    $('#stack thead tr')
    .clone(true)
    .addClass('filters')
    .appendTo('#stack thead');

    var table = $('#stack').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 %}
# Stack
{%- if stack.stackSwitchInfo is not none %}
## Switch Info
{%-     for item in stack.stackSwitchInfo %}
### {{ item.stackMemberNumber }}
#### Priority 
##### Hardware: {{ item.hwPriority }}
##### Switch: {{ item.switchPriority }}
#### Platform: {{ item.platformId }}
#### Role: {{ item.role }}
#### State: {{ item.state }}
#### MAC Address: {{ item.macAddress }}
#### Next Reload: {{ item.numNextReload }}
#### Software Image: {{ item.softwareImage }}
#### Serial Number: {{ item.serialNumber }}
{%-     endfor %}
{%- endif %}
{%-   if stack.stackPortInfo is not none %}
## Port Info
{%-     for item in stack.stackPortInfo %}
### {{ item.name }}
#### Is Synch Ok: {{ item.isSynchOk }}
#### Switchport: {{ item.switchPort }}
#### Neighbor Port: {{ item.neighborPort }}
#### Link OK Changes: {{ item.nrLinkOkChanges }}
#### Stack Cable Length: {{ item.stackCableLengthInfo }}
#### Stack Port Status: {{ item.stackPortOperStatusInfo }}
#### Link Active: {{ item.linkActive }}
#### Link OK: {{ item.linkOk }}
{%-     endfor %}
{%- endif %}
{%-         endif %}
{%-     endif %}
{%- endif %}