不知道如何正确命名。
有没有办法编写一个主模板和许多片段并根据 URL 用户请求注入所需的片段。假设我有/customers/profile和/customers/projects。我想用 2 个{{ define "profile" }}和{{ define "projects" }}片段编写一个主要的customer.html模板文件和一个customer-includes.html文件。然后我想要 2 个处理程序来处理/customers/profile和/customers/projects并执行customer.html模板。但是,当用户转到 URL /customers/profile我想注入主模板{{ template "profile" 。}}如果他去/customers/projects我想注入{{ template "projects" 。}}。做这个的最好方式是什么?我假设我需要在那里使用某种 {{ if / else }} 。如下例所示。但是mby有更好的方法。
{{ if ( eq .Section "customer-profile") }} // Could be replaced with Page ID
{{ template "profile" . }}
{{ else }}
{{ template "projects" . }}
{{ end}}