Skip to main content

template

Macro template 

Source
template!() { /* proc-macro */ }
Expand description

Re-export proc macros from md-tmpl-macros so users can write md_tmpl::include_template! instead of importing md_tmpl_macros separately. Parse and validate an inline template string at compile time and emit a complete module.

Unlike include_template! which reads from a file, this macro takes a string literal containing the full template source (including frontmatter). The => module_name is required because there is no file path from which to derive a name.

The generated module has the same shape as include_template! — see its docs for details.

§Examples

extern crate md_tmpl_core as md_tmpl;
md_tmpl_macros::template!(
    r#"
---
params:
  - name = str
---
Hello {{ name }}!
"# => greeting
);

let output = greeting::Params { name: "World".into() }
    .render()
    .unwrap();
assert_eq!(output, "Hello World!\n");

§Panics

Panics if an env expression cannot be evaluated at macro expansion time.