Fullmoon supports two patterns for complex layouts:
1. Dynamic Template Selection
Pass the name of the template you want to render as a parameter to a wrapper template.
fm.setTemplate("header", "<h1>{% render(content, {title = title}) %}</h1>")
fm.render("header", {title = 'World', content = 'hello_template_name'})
2. Blocks (Inheritance Pattern)
Define a 'layout' template that calls functions stored in the block table. 'Child' templates can then overwrite these functions in the block table before rendering the layout.
Workflow:
- Layout: Defines a block function in
block.name() and calls {% block.name() %} where it should appear. - Child: Defines
{% function block.name() %} ... {% end %} to provide new content, then calls render on the layout.
Note: The block must be explicitly called from the base/layout template to be rendered.
-- Layout template
fm.setTemplate("header", "<h1\>{% function block.greet() %}Hi{% end %}{% block.greet() %}, {%& title %}!</h1>")
-- Child template overwriting the block
fm.setTemplate("hello", "{% function block.greet() %}Hello{% end %}{% render('header', {title=title}) %}")
fm.render("hello", {title = 'World'}) -- renders <h1>Hello, World!</h1>