[−][src]Module ructe::Template_syntax::d_Calling_other_templates
The ability to call other templates for from a template makes both "tag libraries" and "base templates" possible with the same syntax.
Calling other templates
While rust methods can be called as a simple expression, there is a
special syntax for calling other templates:
@:template_name(template_arguments)
.
Also, before calling a template, it has to be imported by a use
statement.
Templates are declared in a templates
module.
So, given something like this in header.rs.html
:
@(title: &str)
<head>
<title>@title</title>
<link rel="stylesheet" href="/my/style.css" type="text/css">
</head>
It can be used like this:
@use super::header;
@()
<html>
@:header("Example")
<body>
<h1>Example</h1>
<p>page content ...</p>
</body>
</html>
It is also possible to send template blocks as parameters to templates.
A structure similar to the above can be created by having something like
this in base_page.rs.html
:
@(title: &str, body: Content)
<html>
<head>
<title>@title</title>
<link rel="stylesheet" href="/my/style.css" type="text/css">
</head>
<body>
<h1>@title</h1>
@:body()
</body>
</html>
And use it like this:
@use super::base_page;
@()
@:base_page("Example", {
<p>page content ...</p>
})