[%- WRAPPER site_wrapper.html 
  title = 'Sections'
-%]
[%- SET 
 p           = c.req.query_params
 count = 0
-%]

[% BLOCK list_subsections %]
  [%- SET 
    p.parent_id = this_section_id
    result      = list_sections( p )
    sections    = result.rows
  -%]
  
  [% IF result.total > 0 %]
    <ul>
      [% IF this_section_id == 'none' %]
        [% SET posts_result = list_posts( limit => 1, section_id => 'none' ) %]
        [% IF posts_result.total > 0 %]
          <li>
            <a href="[%- mount_url -%]/list?section_id=none">
              <i>unsectioned</i>
            </a> ([% posts_result.total %] posts)
          </li>
        [% END %]
      [% END %]
      [% FOREACH section IN sections %]
        [% SET count = count + 1 %]
        <li>
          [% IF section.posts_count > 0 %]
            <a href="[%- mount_url -%]/list?under_section_id=[% section.id %]">
              [% section.name %]
            </a>
          [% ELSE %]
            [% section.name %]
          [% END %] ([% section.posts_count %] posts)
          [% PROCESS list_subsections this_section_id = section.id %]
        </li>
      [% END %]
      
    </ul>
  [% END %]
  
  
[% END %]
  
<div class="blog-post">
  [% PROCESS list_subsections this_section_id = 'none' %]
  
  <br>
  
  [% count %] total sections

</div>


[% END %]