Fix english 7.4 chapter preventing book to be built

This commit is contained in:
Denis Koltsov
2016-11-19 14:08:01 +01:00
parent b19cd5d8d3
commit f5182cb3c4

View File

@@ -75,8 +75,8 @@ If you print `{{.}}` in a template, Go outputs a formatted string of this object
We know how to output a field now. What if the field is an object, and it also has its own fields? How do we print them all in one loop? We can use `{{with …}}…{{end}}` and `{{range …}}{{end}}` for exactly that purpose. We know how to output a field now. What if the field is an object, and it also has its own fields? How do we print them all in one loop? We can use `{{with …}}…{{end}}` and `{{range …}}{{end}}` for exactly that purpose.
- `{{range}}` just like range in Go. - {% raw %}`{{range}}`{% endraw %} just like range in Go.
- `{{with}}` lets you write the same object name once and use `.` as shorthand for it ( ***Similar to `with` in VB*** ). - {% raw %}`{{with}}`{% endraw %} lets you write the same object name once and use `.` as shorthand for it ( ***Similar to `with` in VB*** ).
More examples: More examples:
@@ -305,6 +305,7 @@ Here's a complete example, supposing that we have the following three files: `he
Main template: Main template:
{% raw %}
//header.tmpl //header.tmpl
{{define "header"}} {{define "header"}}
<html> <html>
@@ -334,6 +335,7 @@ Main template:
//When using subtemplating make sure that you have parsed each sub template file, //When using subtemplating make sure that you have parsed each sub template file,
//otherwise the compiler wouldn't understand what to substitute when it reads the {{template "header"}} //otherwise the compiler wouldn't understand what to substitute when it reads the {{template "header"}}
{% endraw %}
Code: Code:
package main package main
@@ -430,10 +432,10 @@ start with the Range operator, then we can give any member of that struct as `{{
Title and a Content, (please note the capital T and C, they are exported names and they need to be capitalised unless you Title and a Content, (please note the capital T and C, they are exported names and they need to be capitalised unless you
want to make them private). want to make them private).
so {{ range .Tasks }} {{ range .Tasks }}
{{ .Title }} {{ .Title }}
{{ .Content }} {{ .Content }}
{{ end }} {{ end }}
This block of code will print each title and content of the Task array. Below is a full example from github.com/thewhitetulip/Tasks home.html template. This block of code will print each title and content of the Task array. Below is a full example from github.com/thewhitetulip/Tasks home.html template.