ExecuteFunc calls f on each template tag (placeholder) occurrence. Returns the number of bytes written to w. This function is optimized for frozen templates. Use ExecuteFunc for constantly changing templates.
(w io.Writer, f TagFunc)
| 121 | // This function is optimized for frozen templates. |
| 122 | // Use ExecuteFunc for constantly changing templates. |
| 123 | func (t *Template) ExecuteFunc(w io.Writer, f TagFunc) (int64, error) { |
| 124 | var nn int64 |
| 125 | |
| 126 | n := len(t.texts) - 1 |
| 127 | if n == -1 { |
| 128 | ni, err := w.Write(stringToBytes(t.template)) |
| 129 | return int64(ni), err |
| 130 | } |
| 131 | |
| 132 | for i := 0; i < n; i++ { |
| 133 | ni, err := w.Write(t.texts[i]) |
| 134 | nn += int64(ni) |
| 135 | if err != nil { |
| 136 | return nn, err |
| 137 | } |
| 138 | |
| 139 | ni, err = f(w, t.tags[i]) |
| 140 | nn += int64(ni) |
| 141 | if err != nil { |
| 142 | return nn, err |
| 143 | } |
| 144 | } |
| 145 | ni, err := w.Write(t.texts[n]) |
| 146 | nn += int64(ni) |
| 147 | return nn, err |
| 148 | } |
| 149 | |
| 150 | // Execute substitutes template tags (placeholders) with the corresponding |
| 151 | // values from the map m and writes the result to the given writer w. |
no test coverage detected