【问题标题】:Golang: custom template function "capture"Golang:自定义模板功能“捕获”
【发布时间】:2014-07-25 08:05:50
【问题描述】:


我想写像Smarty'scapture这样的模板函数。
如何在里面捕获 html

{{capture}}
    ...
{{/capture}}

如何做到这一点?

【问题讨论】:

    标签: function templates go


    【解决方案1】:
    {{define "T1"}}ONE{{end}}
    {{define "T2"}}TWO{{end}}
    {{define "T3"}}{{template "T1"}} {{template "T2"}}{{end}}
    {{template "T3"}}
    

    两个

    【讨论】:

      【解决方案2】:

      您可以在应用程序中执行此操作:为您要捕获的 HTML sn-p 使用模板、渲染它、将其保存为字符串并在后续模板渲染中使用它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-10
        • 1970-01-01
        • 1970-01-01
        • 2016-08-27
        • 1970-01-01
        • 2021-12-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多