[][src]Macro rdxl::xhtml

xhtml!() { /* proc-macro */ }

The xhtml! macro is the primary mechanism for templating in rdxl

xhtml! consumes mixed Rust code and XML markup as input and emits rendered xhtml to a string buffer. Rust code is usually delimited by {{double braces}} or [[double brackets]]. The syn module is used to allow most Rust expressions to be used inside the correct delimited contexts. Control flow structures such as if/else blocks, loops, and let statements may be used inline as well.

Aside from standard XML syntax, custom types may be defined with xtype! and xrender! facilities. This encourages typesafe modular templates to be created and shared.

Use of xhtml! usually looks something like this:

let mut x = 5;

println!("{}",xhtml!(<div>
   {{ x }},
   {{ x = 3; }}
   {{ x }},
   {{ x = 7; }}
   {{ x }},
   {{ let mut y = 2 }}
   {{ y }},
   {{ y = 1; }}
   {{ y }}
   {{ for i in (0..x) {{
      <span>{{i}}</span>
   }} }}
</div>));