Google closure templates 闭包模板-为复杂的“记录”定义创建可重用的别名

Google closure templates 闭包模板-为复杂的“记录”定义创建可重用的别名,google-closure-templates,soy-templates,Google Closure Templates,Soy Templates,我有一个大豆模板,看起来像 {template .fullView} {@param people: list<[age:int, name:string]>} {call .headers} {param people: $queries /} {/call} {call .content} {param people: $queries /} {/call} {/template} {template .headers} {@param

我有一个大豆模板,看起来像

{template .fullView}
  {@param people: list<[age:int, name:string]>}
  {call .headers}
    {param people: $queries /}
  {/call}
  {call .content}
    {param people: $queries /}
  {/call}
{/template}

{template .headers}
  {@param people: list<[age:int, name:string]>}
  # headers
{/template}

{template .content}
  {@param queries: list<[age:int, name:string]>}
  # content
{/template}
{template.fullView}
{@param-people:list}
{call.headers}
{param people:$querys/}
{/call}
{call.content}
{param people:$querys/}
{/call}
{/template}
{template.headers}
{@param-people:list}
#标题
{/template}
{template.content}
{@param查询:列表}
#内容
{/template}
由于“人”的记录定义已变得比年龄和姓名更复杂,因此在所有三个地方更新参数的定义变得单调乏味。是否可以改为创建别名或可在每个模板中重用的内容

{alias [age:int, name:string] as Person}
{template .headers}
  {@param people: list<Person>}
  # headers
{/template}
{alias[age:int,name:string]as Person}
{template.headers}
{@param-people:list}
#标题
{/template}

为什么不为
人定义一个proto呢?似乎还建议使用protos而不是记录:

在许多情况下,定义协议缓冲区优于使用记录 因为它不那么冗长

你可以这样定义一条消息

// syntax: proto3
message Person {
    int32 age = 1;
    string name = 2;
    // more fields here 
}