pub fn render_template(
    name: &str,
    tera: &Tera,
    context: Context,
    theme: &Option<String>,
) -> Result<String> {
    // check if it is in the templates
    if tera.templates.contains_key(name) {
        return tera.render(name, &context).map_err(std::convert::Into::into);
    }

    // check if it is part of a theme
    if let Some(ref t) = *theme {
        let theme_template_name = format!("{}/templates/{}", t, name);
        if tera.templates.contains_key(&theme_template_name) {
            return tera.render(&theme_template_name, &context).map_err(std::convert::Into::into);
        }
    }

    // check if it is part of ZOLA_TERA defaults
    let default_name = format!("__zola_builtins/{}", name);
    if tera.templates.contains_key(&default_name) {
        return tera.render(&default_name, &context).map_err(std::convert::Into::into);
    }

    // maybe it's a default one?
    match name {
        "index.html" | "section.html" => render_default_tpl!(
            name,
            "https://www.getzola.org/documentation/templates/pages-sections/#section-variables"
        ),
        "page.html" => render_default_tpl!(
            name,
            "https://www.getzola.org/documentation/templates/pages-sections/#page-variables"
        ),
        "single.html" | "list.html" => {
            render_default_tpl!(name, "https://www.getzola.org/documentation/templates/taxonomies/")
        }
        _ => bail!("Tried to render `{}` but the template wasn't found", name),
    }
}
/// Renders the given template with the given context, but also ensures that, if the default file
/// is not found, it will look up for the equivalent template for the current theme if there is one.
/// Lastly, if it's a default template (index, section or page), it will just return an empty string
/// to avoid an error if there isn't a template with that name
Renders the given template with the given context, but also ensures that, if the default file
is not found, it will look up for the equivalent template for the current theme if there is one.
Lastly, if it's a default template (index, section or page), it will just return an empty string
to avoid an error if there isn't a template with that name
Renders the given template with the given context but also ensures that if the default file is not found it will look up for the equivalent template for the current theme if there is one . Lastly if it ' s a default template ( index section or page ) it will just return an empty string to avoid an error if there isn ' t a template with that name
pub fn render_template(
    name: &str,
    tera: &Tera,
    context: Context,
    theme: &Option<String>,
) -> Result<String> {
    // check if it is in the templates
    if tera.templates.contains_key(name) {
        return tera.render(name, &context).map_err(std::convert::Into::into);
    }
    // check if it is part of a theme
    if let Some(ref t) = *theme {
        let theme_template_name = format!("{}/templates/{}", t, name);
        if tera.templates.contains_key(&theme_template_name) {
            return tera.render(&theme_template_name, &context).map_err(std::convert::Into::into);
        }
    }
    // check if it is part of ZOLA_TERA defaults
    let default_name = format!("__zola_builtins/{}", name);
    if tera.templates.contains_key(&default_name) {
        return tera.render(&default_name, &context).map_err(std::convert::Into::into);
    }
    // maybe it's a default one?
    match name {
        "index.html" | "section.html" => render_default_tpl!(
            name,
            "https://www.getzola.org/documentation/templates/pages-sections/#section-variables"
        ),
        "page.html" => render_default_tpl!(
            name,
            "https://www.getzola.org/documentation/templates/pages-sections/#page-variables"
        ),
        "single.html" | "list.html" => {
            render_default_tpl!(name, "https://www.getzola.org/documentation/templates/taxonomies/")
        }
        _ => bail!("Tried to render `{}` but the template wasn't found", name),
    }
}
pub fn render_template ( name : & str , tera : & Tera , context : Context , theme : & Option < String > , ) -> Result < String > { // check if it is in the templates if tera . templates . contains_key ( name ) { return tera . render ( name , & context ) . map_err ( std :: convert :: Into :: into ) ; } // check if it is part of a theme if let Some ( ref t ) = * theme { let theme_template_name = format ! ( " " t name ) ; if tera . templates . contains_key ( & theme_template_name ) { return tera . render ( & theme_template_name , & context ) . map_err ( std :: convert :: Into :: into ) ; } } // check if it is part of ZOLA_TERA defaults let default_name = format ! ( " " name ) ; if tera . templates . contains_key ( & default_name ) { return tera . render ( & default_name , & context ) . map_err ( std :: convert :: Into :: into ) ; } // maybe it's a default one? match name { " " | " " => render_default_tpl ! ( name " " ) , " " => render_default_tpl ! ( name " " ) , " " | " " => { render_default_tpl ! ( name " " ) } _ => bail ! ( " " name ) , } }
Renders the given template with the given context, but also ensures that, if the default file
is not found, it will look up for the equivalent template for the current theme if there is one.
Renders the given template with the given context but also ensures that if the default file is not found it will look up for the equivalent template for the current theme if there is one .
name
&str
tera
&Tera
context
Context
theme
&Option<String>
name
&str
tera
&Tera
context
Context
theme
&Option<String>