{{ card_title |> truncate(config.max_title) }}
{{ card_desc |> truncate(150) }}
{% end %} {# Metadata row - conditionally shown #} {% if config.show_meta %} {% end %}{# ================================================================================ Advanced Kida Patterns Showcase (v2) ================================================================================ This file demonstrates the full power of Kida's templating features. Import and use these components as building blocks for complex UIs. FEATURES DEMONSTRATED: - {% def %} Recursive macros for tree traversal - {% embed %} Template composition with block overrides (SEE: card-base.html) - {% cache %} Fragment caching for expensive computations - {% capture %} String building and buffering - {% filter %} Block-level transformations - {% match %} Advanced pattern matching with guards - {% while %} Condition-based loops (NEW in Kida 2.0!) - {% with %} Nil-resilient scope binding - {% unless %} Negative conditionals (cleaner than if not) - {% break %} / {% continue %} Loop control - Range expressions: 1..10, 1..100 by 10 - Pipeline operators (|>) for functional composition KIDA-NATIVE SYNTAX GUIDE: {% let x = 1 %} - Template-scoped variable {% set x = 1 %} - Block-scoped variable (re-assignable) {% export x = 1 %} - Export from inner scope x?.property - Optional chaining (null-safe) x ?? default - Null coalescing value |> filter - Pipeline operator {% end %} - Universal block end (like Go templates) USAGE: {% from 'partials/components/advanced-patterns.html' import tree_view, card_grid, smart_list %} {{ tree_view(site.sections, depth=3) }} ================================================================================ #} {# ============================================================================= RECURSIVE TREE VIEW MACRO Renders hierarchical data (sections, menus, TOC) with arbitrary depth. Demonstrates: {% def %} recursion, {% match %}, {% let %}, nil-resilience ============================================================================= #} {% def tree_view(nodes, depth=3, current_depth=0, node_template='default') %} {% if nodes | length > 0 and current_depth < depth %}
{{ card_desc |> truncate(150) }}
{% end %} {# Metadata row - conditionally shown #} {% if config.show_meta %} {% end %}{{ empty_message ?? t('list.empty', default='No items to display.') }}
{{ excerpt |> truncate(150) }}
{% end %} {% end %} {% block footer %} {% with post?.date as date %} {% end %} {% if post?.author %} {% end %} {% end %} {% block actions %} Read more → {% end %} {% end %} {% end %} {# ============================================================================= WHILE LOOP EXAMPLE (Kida 2.0 Moonshot Feature!) Demonstrates: {% while %} condition-based loops with break/continue ============================================================================= #} {% def countdown_widget(start=10, step=1) %} {# While loops are perfect for condition-based iteration #} {% end %} {# While loop with break condition #} {% def find_first_featured(posts, max_search=100) %} {# Search through posts until we find a featured one #} {% let found = none %} {% let index = 0 %} {% let post_list = posts ?? [] %} {% while index < post_list | length and index < max_search %} {% let post = post_list[index] %} {% if post?.featured %} {% let found = post %} {% break %} {% end %} {% let index = index + 1 %} {% end %} {% if found %}Found at position {{ index + 1 }}
No featured post found in first {{ index }} posts.
{% end %} {% end %} {# While loop with continue for filtering #} {% def filtered_render(items, min_score=0) %} {# Render items that meet minimum score, skip others #}