Search code examples
gobeego

Beego: How do I use If-else conditions in templates?


How do I use conditions in beego's templating system? Or is it just expected that we use this for templating instead?

https://github.com/ipfans/beego-pongo2.v2

I'd like to try my best first to do this Beego's way before latching something else on here. I mean....surely conditional rendering was thought of when creating beego's stock templating system right?

While we're at it what about looping?


Solution

  • From Beego Template Parsing docs:

    Beego uses Go’s builtin package html/template as the template parser.

    Beego WebIM Sample:

    <script src="/static/js/jquery-1.10.1.min.js"></script>
    {{if .IsLongPolling}}
    <script src="/static/js/longpolling.js"></script>
    {{else}}
    <script src="/static/js/websocket.js"></script>
    {{end}}