{"record":{"id":"d6d63d53ecc84283","repo":"getzola/zola","slug":"either-a-templates-folder-or-a-theme-is-require","errorCode":null,"errorMessage":"Either a `templates/` folder or a theme is required","messagePattern":"Either a `templates/` folder or a theme is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"components/templates/src/lib.rs","lineNumber":139,"sourceCode":"\n    // Add builtin templates\n    for (name, content) in BUILTIN_TEMPLATES {\n        templates.push((name.to_string(), content.to_string()));\n    }\n\n    // Validate theme exists if configured\n    let site_tpl_dir = path.join(\"templates\");\n    let theme_tpl_dir =\n        config.theme.as_ref().map(|t| path.join(\"themes\").join(t).join(\"templates\"));\n\n    if let Some(ref theme_dir) = theme_tpl_dir\n        && !theme_dir.exists()\n    {\n        bail!(\"Theme `{}` is missing a templates folder\", config.theme.as_ref().unwrap());\n    }\n\n    if !site_tpl_dir.exists() && theme_tpl_dir.is_none() {\n        bail!(\"Either a `templates/` folder or a theme is required\");\n    }\n\n    // Load theme templates first (lower priority)\n    if let Some(ref theme) = config.theme {\n        let pattern = format!(\n            \"{}/themes/{theme}/templates/**/*.{{html,xml,md,txt,json,ics}}\",\n            glob_base(path)\n        );\n        for (file_path, name) in tera::load_from_glob(&pattern)? {\n            // \"page.html\" → \"sample/templates/page.html\"\n            let name = format!(\"{theme}/templates/{name}\");\n            let content = fs::read_to_string(&file_path)\n                .with_context(|| format!(\"Failed to read '{}'\", file_path.display()))?;\n            templates.push((name, content));\n        }\n    }\n\n    // Load site templates (higher priority, will override theme templates)","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/getzola/zola/blob/61d30828217957120309db657950224edf9707e2/components/templates/src/lib.rs#L121-L157","documentation":"`load_tera` requires at least one template source: either a `templates/` directory at the site root or a configured theme providing one. If neither exists it bails with this message, since Tera would have no templates to load.","triggerScenarios":"Running a site build/serve where `templates/` does not exist at the project root AND `config.theme` is None/unset in config.toml.","commonSituations":"Freshly initialized or emptied project where the templates folder was deleted or never created; running zola from the wrong directory; config.toml missing the `theme` key after removing templates.","solutions":["Create a `templates/` directory at the site root with at least an index.html","Or set `theme = \"...\"` in config.toml with the theme installed under `themes/`","Run the command from the correct project root directory"],"exampleFix":"// before\n# no templates/ dir, no theme set\n// after\n$ mkdir templates && echo '...' > templates/index.html\n# or set theme = \"hyde\" in config.toml","handlingStrategy":"validation","validationCode":"let has_templates = Path::new(\"templates\").is_dir();\nlet has_theme = config.theme.is_some();\nif !has_templates && !has_theme {\n    panic!(\"create templates/ or set theme in config.toml\");\n}","typeGuard":null,"tryCatchPattern":"match load_tera(base_path, &config) {\n    Ok(t) => use(t),\n    Err(e) if e.to_string().contains(\"Either a `templates/` folder\") => {\n        eprintln!(\"run from project root; create templates/ or set a theme\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always run zola from the site root containing config.toml","Keep at least templates/index.html in the project","Commit the templates/ directory (or theme config) to version control"],"tags":["rust","zola","templates","configuration"],"backgroundTag":"missing-templates-folder","analyzedSha":"61d30828217957120309db657950224edf9707e2","analyzedAt":"2026-09-03T14:39:09.727Z","contentChangedAt":"2026-09-03T14:39:09.727Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}