tmpl.Execute and sub-file golang

前端 未结 1 820
旧巷少年郎
旧巷少年郎 2021-01-22 05:48

I need help. I need to use \"html/template\"\'s marking ({{.Title}}, example) in sub-files(\"article.html\", example in my text):

相关标签:
1条回答
  • 2021-01-22 06:18

    In your core.tmpl you have to use

    {{template "article" .}}
    

    If you don't specify the . at the end, the template will be executed with nil data. Specifying the . will pass the value of . to the invoked template.

    Quoting from the text/template package documentation, Actions section:

    {{template "name"}}
        The template with the specified name is executed with nil data.
    
    {{template "name" pipeline}}
        The template with the specified name is executed with dot set
        to the value of the pipeline.
    
    0 讨论(0)
提交回复
热议问题