简体   繁体   English

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

[英]Closure templates - create a reusable alias for complicated `record` definition

I have a soy template that looks like我有一个看起来像的大豆模板

{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}

As the record definition for "people" has become more complex than just age and name it has become tedious to update the definition of the param in all three places.由于“人”的记录定义变得比年龄和姓名更复杂,因此更新所有三个地方的参数定义变得乏味。 Is it possible to instead create an alias or something that could be reused in each template?是否可以创建一个别名或可以在每个模板中重用的东西?

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

Why not define a proto for Person instead?为什么不为Person定义一个原型呢? The docs also seems to recommend using protos over records: 文档似乎还建议在记录上使用 protos:

In many cases, defining a protocol buffer is superior to using records since it is less verbose.在许多情况下,定义协议缓冲区优于使用记录,因为它不那么冗长。

So you could define a message like this?所以你可以定义这样的消息吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM