本文整理汇总了Golang中html/template.ExecuteTemplate函数的典型用法代码示例。如果您正苦于以下问题:Golang ExecuteTemplate函数的具体用法?Golang ExecuteTemplate怎么用?Golang ExecuteTemplate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了ExecuteTemplate函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: SponsorSlidesGetHandler

// Shows the sponsor slides configuration page.
func SponsorSlidesGetHandler(w http.ResponseWriter, r *http.Request) {
    if !UserIsAdmin(w, r) {
        return
    }

    template, err := template.ParseFiles("templates/setup_sponsor_slides.html", "templates/base.html")
    if err != nil {
        handleWebErr(w, err)
        return
    }
    sponsorSlides, err := db.GetAllSponsorSlides()
    if err != nil {
        handleWebErr(w, err)
        return
    }
    data := struct {
        *EventSettings
        SponsorSlides []SponsorSlide
    }{eventSettings, sponsorSlides}
    err = template.ExecuteTemplate(w, "base", data)
    if err != nil {
        handleWebErr(w, err)
        return
    }
}

开发者ID:fangeugene,项目名称:cheesy-arena,代码行数:26,代码来源:setup_sponsor_slides.go

示例2: Publish

func (h *HTMLRedirectAlias) Publish(path string, permalink string, page interface{}) (err error) {
    if path, err = h.Translate(path); err != nil {
        jww.ERROR.Printf("%s, skipping.", err)
        return nil
    }

    t := "alias"
    if strings.HasSuffix(path, ".xhtml") {
        t = "alias-xhtml"
    }

    template := defaultAliasTemplates
    if h.Templates != nil {
        template = h.Templates
        t = "alias.html"
    }

    buffer := new(bytes.Buffer)
    err = template.ExecuteTemplate(buffer, t, &AliasNode{permalink, page})
    if err != nil {
        return
    }

    return helpers.WriteToDisk(path, buffer, hugofs.Destination())
}

开发者ID:digitalcraftsman,项目名称:hugo,代码行数:25,代码来源:htmlredirect.go

示例3: defaultFormatFunc

func defaultFormatFunc(h http.HTTP) http.Formatter {

    var bt []byte
    var err error

    hc := h.(*HipChat)
    b := new(bytes.Buffer)
    template := hc.Template()

    body := new(Body)
    body.Notify = true

    return func(e *log.Entry) []byte {

        bt = bt[0:0]
        b.Reset()
        body.From = e.ApplicationID
        body.Color = hc.GetDisplayColor(e.Level)

        if err = template.ExecuteTemplate(b, "hipchat", e); err != nil {
            log.WithFields(log.F("error", err)).Error("Error parsing HipChat handler template")
        }

        body.Message = b.String()

        // shouldn't be possible to fail here
        // at least with the default handler...
        bt, _ = json.Marshal(body)

        return bt
    }
}

开发者ID:go-playground,项目名称:log,代码行数:32,代码来源:hipchat.go

示例4: LowerThirdsGetHandler

// Shows the lower third configuration page.
func LowerThirdsGetHandler(w http.ResponseWriter, r *http.Request) {
    if !UserIsAdmin(w, r) {
        return
    }

    template, err := template.ParseFiles("templates/setup_lower_thirds.html", "templates/base.html")
    if err != nil {
        handleWebErr(w, err)
        return
    }
    lowerThirds, err := db.GetAllLowerThirds()
    if err != nil {
        handleWebErr(w, err)
        return
    }
    data := struct {
        *EventSettings
        LowerThirds []LowerThird
    }{eventSettings, lowerThirds}
    err = template.ExecuteTemplate(w, "base", data)
    if err != nil {
        handleWebErr(w, err)
        return
    }
}

开发者ID:fangeugene,项目名称:cheesy-arena,代码行数:26,代码来源:setup_lower_thirds.go

示例5: TeamEditGetHandler

// Shows the page to edit a team's fields.
func TeamEditGetHandler(w http.ResponseWriter, r *http.Request) {
    if !UserIsAdmin(w, r) {
        return
    }

    vars := mux.Vars(r)
    teamId, _ := strconv.Atoi(vars["id"])
    team, err := db.GetTeamById(teamId)
    if err != nil {
        handleWebErr(w, err)
        return
    }
    if team == nil {
        http.Error(w, fmt.Sprintf("Error: No such team: %d", teamId), 400)
        return
    }

    template, err := template.ParseFiles("templates/edit_team.html", "templates/base.html")
    if err != nil {
        handleWebErr(w, err)
        return
    }
    data := struct {
        *EventSettings
        *Team
    }{eventSettings, team}
    err = template.ExecuteTemplate(w, "base", data)
    if err != nil {
        handleWebErr(w, err)
        return
    }
}

开发者ID:fangeugene,项目名称:cheesy-arena,代码行数:33,代码来源:setup_teams.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng