update docs

This commit is contained in:
Manuel Gugger 2023-07-17 18:04:52 +02:00
parent 2c2e5ce69d
commit 3dcc17b6af

View File

@ -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. 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 ## Custom Index
A custom *custom_index.html* view can be defined as follows by extending the base template: 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. 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 ```rust
use actix_admin::prelude::*;
async fn custom_index( async fn custom_index(
session: Session, session: Session,
data: web::Data<AppState> tera: web::Data<Tera>,
actix_admin: web::Data<ActixAdmin> actix_admin: web::Data<ActixAdmin>
) -> Result<HttpResponse, Error> { ) -> Result<HttpResponse, Error> {
let mut ctx = Context::new(); let mut ctx = get_admin_ctx(session, &actix_admin);
ctx.extend(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)) Ok(HttpResponse::Ok().content_type("text/html").body(body))
} }