10.10.3 JSON View Templates 5.1.2

(Quick Reference) # 10.10.3 JSON View Templates Version: 5.1.2 ## 10.10.3 JSON View Templates You can define templates starting with underscore `_`. For example given the following template called `_person.gson`:
    model {
        Person person
    }
    json {
        name person.name
        age person.age
    }
You can render it with a view as follows:
    model {
        Family family
    }
    json {
        name family.father.name
        age family.father.age
        oldestChild g.render(template:"person", model:[person: family.children.max { Person p -> p.age } ])
        children g.render(template:"person", collection: family.children, var:'person')
    }
Alternatively for a more concise way to invoke templates, using the tmpl variable:
    model {
        Family family
    }
    json {
        name family.father.name
        age family.father.age
        oldestChild tmpl.person( family.children.max { Person p -> p.age } ] )
        children tmpl.person( family.children )
    }
| Quick Reference (hide)