macro_rules! register_page_type {
($ty:ty) => { ... };
}Expand description
Submit a PageTypeHandlerRegistration for $ty to the global
inventory.
$ty must implement both PageTypeHandler and Default —
the macro instantiates one through <$ty>::default() per call to
registered_handlers.
§Example
ⓘ
use rustango_cms::{register_page_type, PageTypeHandler};
#[derive(Default)]
pub struct ArticlePage;
#[async_trait::async_trait]
impl PageTypeHandler for ArticlePage {
fn app_label(&self) -> &'static str { "blog" }
fn type_name(&self) -> &'static str { "ArticlePage" }
fn verbose_name(&self) -> &'static str { "Article" }
fn default_template(&self) -> &'static str { "blog/article.html" }
}
register_page_type!(ArticlePage);§Per-type extension tables
For typed extension data (e.g. an article’s body, hero image),
author a sibling #[derive(Model)] struct with a one-to-one FK
back to cms_page:
ⓘ
use rustango::sql::Auto;
use rustango::Model;
#[derive(Model)]
#[rustango(table = "cms_article_page", app = "blog")]
pub struct ArticlePageExt {
#[rustango(primary_key, fk = "cms_page", on = "id", unique)]
pub page_id: i64,
pub body_markdown: String,
pub hero_image: Option<String>,
}The host crate ships this in its own migrations/ directory;
discover_migration_dirs picks it up alongside the framework’s.
Override PageTypeHandler::load_extension to fetch the row and
return it as JSON for the renderer’s Tera context.