You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Quarto混合导航侧边栏始终显示问题求助

解决Quarto混合导航侧边栏始终显示的问题

你的问题核心是没给侧边栏设置显示触发条件,默认配置下侧边栏会全局显示,不管当前页面是不是教程内容。要实现只有点击导航栏“Tutorial”时才显示侧边栏,需要做两处修改:

  1. 给侧边栏添加when字段,指定仅当访问教程目录下的页面时才显示侧边栏
  2. 完善导航栏中“Tutorial”的跳转目标,指向教程的起始页面

修改后的YAML配置如下:

project:
  type: website
  resources: tutorial.pdf, tutorial.R

website:
  title: "test.org"

  navbar:
    background: secondary
    search: true
    left:
      - text: "About"
        file: index.qmd
      - text: "Tutorial"
        file: tutorial/before.qmd  # 指定教程起始页面

  sidebar:
    - title: "Tutorial"
      style: "docked"
      background: light
      when: tutorial/**  # 仅匹配tutorial目录下的所有页面
      contents:
        - tutorial/before.qmd
        - tutorial/loading_data.qmd

format:
  html:
    theme: cosmo
    css: styles.css
    toc: true

关键修改说明:

  • when: tutorial/**:用通配符匹配tutorial目录下的所有页面,只有进入这些页面时,侧边栏才会显示
  • 给导航栏的“Tutorial”添加file属性,点击后直接跳转到教程的第一个页面,此时侧边栏会自动触发显示;访问“About”页面时,因不匹配tutorial/**路径,侧边栏会自动隐藏

内容的提问来源于stack exchange,提问作者Julian Karch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 03:42:05