{%- if filetype_loop == 0 %}Name,Hierarchy Name,Site ID,Instance Tenant ID,Site Hierarchy ID,Type,Namespace,Country,Address,Latitude,Longitude,ETA Ready
{%-     for site in sites %}{%- for info in site.additionalInfo %}
{{ site.name }},{{ site.siteNameHierarchy }},{{ site.id }},{{ site.instanceTenantId }},{{ site.siteHierarchy }},{{ info.attributes.type | default("N/A") }},{{ info.nameSpace | default("N/A") }},{{ info.attributes.country | default("N/A") }},{{ info.attributes.address | replace(","," ") | default("N/A")}},{{ info.attributes.latitude | default("N/A") }},{{ info.attributes.longitude | default("N/A") }},{{ info.attributes.ETAReady | default("N/A") }}
{%-     endfor %}{%- endfor%}
{%- else %}
{%-     if filetype_loop == 1 %}
# Sites
| Name | Hierarchy Name | Site ID | Instance Tenant ID | Site Hierarchy ID | Type | Namespace | Country | Address | Latitude | Longitude | ETA Ready |
| ---- | -------------- | ------- | ------------------ | ----------------- | ---- | --------- | ------- | ------- | -------- | --------- | --------- |
{%-         for site in sites %}{%- for info in site.additionalInfo %}
| {{ site.name }} | {{ site.siteNameHierarchy }} | {{ site.id }} | {{ site.instanceTenantId }} | {{ site.siteHierarchy }} | {{ info.attributes.type | default("N/A") }} | {{ info.nameSpace | default("N/A") }} | {{ info.attributes.country | default("N/A") }} | {{ info.attributes.address | replace(","," ") | default("N/A")}} | {{ info.attributes.latitude | default("N/A") }} | {{ info.attributes.longitude | default("N/A") }} | {{ info.attributes.ETAReady | default("N/A") }} |
{%-         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">
    <title>{% block title %}{% endblock %}</title>
</head>
<body>
<h1>DNAC Sites</h1>
<table id = "sites">
  <thead>
    <tr>
      <th>Name</th>
      <th>Hierarchy Name</th>
      <th>Site ID</th>
      <th>Instance Tenant ID</th>
      <th>Site Hierarchy ID</th>
      <th>Type</th>
      <th>Namespace</th>
      <th>Country</th>
      <th>Address</th>
      <th>Latitude</th>
      <th>Longitude</th>
      <th>ETA Ready</th>
    </tr>
  </thead>
  <tbody>
{%-         for site in sites %}{%- for info in site.additionalInfo %}
  <tr>
    <td>{{ site.name }}</td>
    <td>{{ site.siteNameHierarchy }}</td>
    <td>{{ site.id }}</td>
    <td>{{ site.instanceTenantId }}</td>
    <td>{{ site.siteHierarchy }}</td>
    <td>{{ info.attributes.type | default("N/A") }}</td>
    <td>{{ info.nameSpace | default("N/A") }}</td>
    <td>{{ info.attributes.country | default("N/A") }}</td>
    <td>{{ info.attributes.address | replace(","," ") | default("N/A")}}</td>
    <td>{{ info.attributes.latitude | default("N/A") }}</td>
    <td>{{ info.attributes.longitude | default("N/A") }}</td>
    <td>{{ info.attributes.ETAReady | default("N/A") }}</td>
  </tr>
{%-             endfor %}{% endfor %}
  </tbody>
</table>
<script type = "text/javascript">
  $(document).ready(function(){
    $('#sites thead tr')
    .clone(true)
    .addClass('filters')
    .appendTo('#sites thead');

    var table = $('#sites').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 %}
# Sites
{%-             for site in sites %}
## {{ site.name }}
### Site Hierarchy Name: {{ site.siteNameHierarchy }}
### IDs
#### ID: {{ site.id }}
#### Instance Tenant ID: {{ site.instanceTenantId }}
#### Site Hierarchy ID: {{ site.siteHierarchy }}
{%-                 if site.additionalInfo %}
{%-                     for info in site.additionalInfo %}
{%-                         if info.attributes.type %}
### Type: {{ info.attributes.type }}
{%-                         endif %}
{%-                         if info.nameSpace == "UMBRELLA" %}
### Umbrella
{%-                             for att in info.attributes %}
#### Attribute: {{ info.attributes }}
{%-                             endfor %}
{%-                         endif %}
{%-                         if info.nameSpace == "Location" %}
### Location
{%-                             if info.attributes.type == "area" %}
#### Type: {{ info.attributes.type }}
{%-                             else %}
#### Country: {{ info.attributes.country }}
#### Address: {{ info.attributes.address }}
#### Latitude: {{ info.attributes.latitude }}
#### Longitude: {{ info.attributes.longitude }}
#### Type: {{ info.attributes.type }}
{%-                             endif %}
{%-                         endif %}
{%-                         if info.nameSpace == "ETA" %}
### ETA
#### Ready: {{ info.attributes.ETAReady }}
{%-                         endif %}
{%-                     endfor %}
{%-                 endif %}
{%-             endfor %}
{%-         endif %}
{%-     endif %}
{%- endif %}