From 3dcc17b6af213bb937ec07e0793abc223a3252a7 Mon Sep 17 00:00:00 2001 From: Manuel Gugger Date: Mon, 17 Jul 2023 18:04:52 +0200 Subject: [PATCH] update docs --- docs/content/docs/custom-handler.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/content/docs/custom-handler.md b/docs/content/docs/custom-handler.md index e502db7..e222ad6 100644 --- a/docs/content/docs/custom-handler.md +++ b/docs/content/docs/custom-handler.md @@ -9,6 +9,14 @@ weight: 3 While the derived models create predefined routes and views, custom routes can be added to the admin interface and also base templates can be extended. +## Extend tera instances with base templates from actix-admin + +```rust +let mut tera = Tera::parse("templates/**/*.html").unwrap(); +tera.extend(&actix_admin_builder.get_actix_admin().tera).unwrap(); +let _tera_res = tera.build_inheritance_chains(); +``` + ## Custom Index A custom *custom_index.html* view can be defined as follows by extending the base template: @@ -22,16 +30,18 @@ A custom *custom_index.html* view can be defined as follows by extending the bas To display the *custom_index.html*, define the corresponding function which extends the current tera context from actix-admin and also uses the actix-admin tera instance to render the custom index function. ```rust +use actix_admin::prelude::*; + async fn custom_index( session: Session, - data: web::Data + tera: web::Data, actix_admin: web::Data ) -> Result { - let mut ctx = Context::new(); - ctx.extend(get_admin_ctx(session, &actix_admin)); + let mut ctx = get_admin_ctx(session, &actix_admin); + ctx.insert("your_own_key", "your_own_value"); - let body = data.tmpl.render("custom_index.html", &ctx).unwrap(); + let body = tera.render("custom_index.html", &ctx).unwrap(); Ok(HttpResponse::Ok().content_type("text/html").body(body)) }