Child Theme with Sidebar Customization

manual customization grav

Custom Quark 2 Child Theme (cstm-quark2) Reference

1. Folder & File Structure

Your child theme overrides quark2 safely so theme updates won't erase your changes:

  • user/themes/cstm-quark2/blueprints.yaml — Registers the theme in the Grav Admin panel.
  • user/themes/cstm-quark2/cstm-quark2.yaml — Holds Quark 2 default settings + streams: inheritance paths (user/themes/cstm-quark2 -> user/themes/quark2).
  • user/themes/cstm-quark2/cstm-quark2.php — Extends Grav\Theme\Quark2.
  • user/themes/cstm-quark2/templates/partials/sidebar.html.twig — Custom sidebar supporting dynamic Categories & Tags for both /blog and /documents.

2. Sidebar Twig (templates/partials/sidebar.html.twig)

Switches taxonomy filtering dynamically based on the active route (/documents vs /blog) while avoiding null boolean errors in PHP 8+:

TWIG

{% set blog_url = blog_url ?: theme_var('blog-page')|default('/blog') %}
{% set docs_url = '/documents' %}
{% set is_docs = page.route starts with docs_url %}

{% set base_params = is_docs 
    ? {'base_url': docs_url, 'children_only': false, 'of_page': page.find(docs_url)} 
    : {'base_url': blog_url} 
%}

{% if config.plugins.taxonomylist.enabled %}
<div class="sidebar-content">
    <h4>Categories</h4>
    {% include 'partials/taxonomylist.html.twig' with base_params|merge({'taxonomy': 'category'}) %}
</div>

<div class="sidebar-content">
    <h4>{{ 'THEME_QUARK2.SIDEBAR.POPULAR_TAGS.HEADLINE'|t }}</h4>
    {% include 'partials/taxonomylist.html.twig' with base_params|merge({'taxonomy': 'tag'}) %}
</div>
{% endif %}


3. Page Requirements

  • Parent Section Page (03.documents/blog.md) — Must use the blog template (not default.md) and include a collection with URL taxonomy filtering enabled:
    YAML
    ---
    title: Documentation
    content:
      items: '@self.descendants'
      limit: 10
      order:
          by: date
          dir: desc
      url_taxonomy_filters: true
    ---
    
  • Individual Doc Pages — Assign taxonomies in frontmatter:
    YAML
    ---
    title: My Document
    taxonomy:
      category: [Guides]
      tag: [setup, basics]
    ---
    

4. Quick Maintenance Commands

  • Clear cache after Twig/YAML edits: bin/grav clearcache
  • Create future child themes automatically: bin/plugin devtools new-theme (choose inheritance)