Navigation Functions

Functions for navigating sections and checking page existence

1 min read 168 words

These global functions simplify common navigation patterns.

get_section

Get a section by its path. Cleaner alternative tosite.get_section_by_path().

{% let docs = get_section('docs') %}
{% if docs %}
  <h2>{{ docs.title }}</h2>
  {% for page in docs.pages |> sort_by('weight') %}
    <a href="{{ page.url }}">{{ page.title }}</a>
  {% end %}
{% end %}

section_pages

Get pages from a section directly. Combinesget_section()with.pagesaccess.

{# Non-recursive (direct children only) #}
{% for page in section_pages('docs') |> sort_by('weight') %}
  <a href="{{ page.url }}">{{ page.title }}</a>
{% end %}

{# Recursive (include all nested pages) #}
{% for page in section_pages('docs', recursive=true) %}
  <a href="{{ page.url }}">{{ page.title }}</a>
{% end %}

page_exists

Check if a page exists without loading it. More efficient thanget_page()for conditional rendering.

{% if page_exists('guides/advanced') %}
  <a href="/guides/advanced/">Advanced Guide Available</a>
{% end %}

{# Works with or without .md extension #}
{% if page_exists('docs/getting-started.md') %}...{% end %}
{% if page_exists('docs/getting-started') %}...{% end %}