“Block”类型的模板函数

huangapple go评论70阅读模式
英文:

"Block"-type template functions

问题

使用http/template,是否可以定义一个类似内置的definerange的“块”类型函数?例如,我想创建一个类似下面的函数:

<div class="page">
  {{doThing}}
    这里有大量的文本...
  {{end}}
</div>

我知道可以通过{{ doThing "这里有大量的文本..." }}来实现,但那不是我想要的。

英文:

Using http/template is it possible to define a "block"-type function that work like the built-in define or range? For example, I'd like to make a function that works like:

&lt;div class=&quot;page&quot;&gt;
  {{doThing}}
    Large amount of text here...
  {{end}}
&lt;/div&gt;

I know I can make it work with {{ doThing &quot;Large amount of text here...&quot; }}, but that's not quite what I want.

答案1

得分: 0

无法编写一个类似内置的define或range操作的块类型函数。

英文:

It is not possible to write a block-type function that works like the built-in define or range actions.

huangapple
  • 本文由 发表于 2016年4月3日 00:09:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/36375596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定