HTML builds up the response from the specified template and bindings.
(w io.Writer, status int, name string, binding interface{}, htmlOpt ...HTMLOptions)
| 515 | |
| 516 | // HTML builds up the response from the specified template and bindings. |
| 517 | func (r *Render) HTML(w io.Writer, status int, name string, binding interface{}, htmlOpt ...HTMLOptions) error { |
| 518 | // If we are in development mode, recompile the templates on every HTML request. |
| 519 | r.lock.RLock() // rlock here because we're reading the hasWatcher |
| 520 | if r.opt.IsDevelopment && !r.hasWatcher { |
| 521 | r.lock.RUnlock() // runlock here because CompileTemplates will lock |
| 522 | r.CompileTemplates() |
| 523 | r.lock.RLock() |
| 524 | } |
| 525 | |
| 526 | templates := r.templates |
| 527 | r.lock.RUnlock() |
| 528 | |
| 529 | opt := r.prepareHTMLOptions(htmlOpt) |
| 530 | if tpl := templates.Lookup(name); tpl != nil { |
| 531 | if len(opt.Layout) > 0 { |
| 532 | tpl.Funcs(r.layoutFuncs(templates, name, binding)) |
| 533 | name = opt.Layout |
| 534 | } |
| 535 | |
| 536 | if len(opt.Funcs) > 0 { |
| 537 | tpl.Funcs(opt.Funcs) |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | ct := r.opt.HTMLContentType + r.compiledCharset |
| 542 | if opt.ContentType != "" { |
| 543 | ct = opt.ContentType |
| 544 | } |
| 545 | |
| 546 | head := Head{ |
| 547 | ContentType: ct, |
| 548 | Status: status, |
| 549 | } |
| 550 | |
| 551 | h := HTML{ |
| 552 | Head: head, |
| 553 | Name: name, |
| 554 | Templates: templates, |
| 555 | bp: r.opt.BufferPool, |
| 556 | } |
| 557 | |
| 558 | return r.Render(w, h, binding) |
| 559 | } |
| 560 | |
| 561 | // JSON marshals the given interface object and writes the JSON response. |
| 562 | func (r *Render) JSON(w io.Writer, status int, v interface{}, opts ...CallOptions) error { |