macro_rules! macro_render_layout {
    ($layout:expr, $template_path:expr, $context:expr) => { ... };
}
Expand description

macro_render_layout Macro

This macro selects and renders a specified layout with a given context.

  • $layout: The desired layout name (e.g., “contact”, “index”, “page”). If a template file corresponding to $layout.html exists in the template directory, it will be used. Otherwise, the macro falls back to predefined mappings.

  • $template_path: The path to the directory containing the template files.

  • $context: The context to be rendered into the template.

Behaviour:

  1. If a file named $layout.html exists in $template_path, it will be used as the template.
  2. If no such file exists, the macro checks for predefined layout names:
    • “contact” maps to “contact.html”
    • “index” maps to “index.html”
    • “page” maps to “page.html”
  3. If $layout is unrecognized and doesn’t correspond to a file in the template directory, the macro defaults to using “index.html”.

Returns:

The macro returns a rendered string using the selected template and provided context.