Beego: Beego nested template

Created on 8 Sep 2016  ·  2Comments  ·  Source: astaxie/beego

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go and beego are you using (bee version)?
> ── Beego     : 1.7.0
> ├── GoVersion : go1.6.2
> ├── GOOS      : linux
> ├── GOARCH    : amd64
> ├── NumCPU    : 2
> ├── GOPATH    : /root/Go
> ├── GOROOT    : /usr/local/go
> ├── Compiler  : gc
> └── Date      : Thursday, 8 Sep 2016
  1. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/Go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
  1. What did you do?
    I'm trying to do a very simples template as a test and don't know how to make it work. I used the default index.tpl and splitted it in index.tpl and footer.tpl. On the index.tpl I placed o copy of the footer text which uses variables {{.Website}} and {{.Email}}

index.tpl

<!DOCTYPE html>

<html>
    {{template "head.tpl"}}
    <body>
      <header>
        <h1 class="logo">Welcome to Beego</h1>
        <div class="description">
             <a href="http://{{.Website}}">{{.Website}}</a> /
             Contact me:
             <a class="email" href="mailto:{{.Email}}">{{.Email}}</a>
        </div>
      </header>
    <div>
    </div>
    {{template "footer.tpl"}}
      <div class="backdrop"></div>
    </body>
</html>

and footer.tpl

 <footer>
   <div class="author">
     Official website:
     <a href="http://{{.Website}}">{{.Website}}</a> /
     Contact me:
     <a class="email" href="mailto:{{.Email}}">{{.Email}}</a>
   </div>
 </footer>
  1. What did you expect to see?
    The value of both variables on both files
    Am I wrong expecting it? If so, how would be the currect way to do this?
  2. What did you see instead?
    The {{.Website}} and {{.Email}} variables works on the index.tpl file, but doesn't work on footer.tpl.

Most helpful comment

{{template "footer.tpl" .}} you miss the last . to pass the params to nest template

All 2 comments

{{template "footer.tpl" .}} you miss the last . to pass the params to nest template

非常感谢你 (google translator. hehe, hope it is right)
Thanks for taking your time to answer a dummy question like that. And sorry by the way for making you wast your time. hehe

Was this page helpful?
0 / 5 - 0 ratings