diff --git a/docs/en/Quickstart.md b/docs/en/Quickstart.md index add38678..2b413b37 100644 --- a/docs/en/Quickstart.md +++ b/docs/en/Quickstart.md @@ -10,8 +10,8 @@ Hey, you say you've never heard about Beego and don't know how to use it? Don't - [Static files](#static-files) - [Filter and middleware](#filter-and-middleware) - [Controller](#controller) -- [Template](#-8) -- [Handle request](#request) +- [Template](#template) +- [Handle request](#handle-request) - [Redirect and error](#-15) - [Handle response](#response) - [Sessions](#sessions) @@ -290,64 +290,65 @@ Overload all methods for all customized logic processes, let's see an example: this.Ctx.Redirect(302, "/admin/index") } -## 模板处理 -### 模板目录 -beego中默认的模板目录是`views`,用户可以把你的模板文件放到该目录下,beego会自动在该目录下的所有模板文件进行解析并缓存,开发模式下会每次重新解析,不做缓存。当然用户可以通过如下的方式改变模板的目录: +##Template +###Template directory +Beego uses `views` as the default directory for template files, parses and caches them as needed(cache is not enable in develop mode), but you can **change**(because only one directory can be used for template files) its directory using following code: beego.ViewsPath = "/myviewpath" -### 自动渲染 -beego中用户无需手动的调用渲染输出模板,beego会自动的在调用玩相应的method方法之后调用Render函数,当然如果你的应用是不需要模板输出的,那么你可以在配置文件或者在main.go中设置关闭自动渲染。 -配置文件配置如下: +###Auto-render +You don't need to call render function manually, Beego calls it automatically after corresponding methods executed. If your application is somehow doesn't need templates, you can disable this feature either in code of `main.go` or configuration file. + +To disable auto-render in configuration file: autorender = false -main.go文件中设置如下: +To disable auto-render in `main.go`(before you call `beego.Run()` to run the application): beego.AutoRender = false -### 模板数据 -模板中的数据是通过在Controller中`this.Data`获取的,所以如果你想在模板中获取内容`{{.Content}}`,那么你需要在Controller中如下设置: +###Template data +You can use `this.Data` in controller methods to access the data in templates. Suppose you want to get content of `{{.Content}}`, you can use following code to do this: this.Data["Context"] = "value" -### 模板名称 -beego采用了Go语言内置的模板引擎,所有模板的语法和Go的一模一样,至于如何写模板文件,详细的请参考[模板教程](https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/07.4.md)。 +###Template name +Beego uses built-in template engine of Go, so there is no different in syntax. As for how to write template file, please visit [Template tutorial](https://github.com/Unknwon/build-web-application-with-golang_EN/blob/master/eBook/07.4.md)。 -用户通过在Controller的对应方法中设置相应的模板名称,beego会自动的在viewpath目录下查询该文件并渲染,例如下面的设置,beego会在admin下面找add.tpl文件进行渲染: +Beego parses template files in `viewpath` and render it after you set the name of the template file in controller methods. For example, Beego finds the file `add.tpl` in directory `admin` in following code: this.TplNames = "admin/add.tpl" -我们看到上面的模板后缀名是tpl,beego默认情况下支持tpl和html后缀名的模板文件,如果你的后缀名不是这两种,请进行如下设置: +Beego supports two kinds of extensions for template files, which are `tpl` and `html`, if you want to use other extensions, you have to use following code to let Beego know: - beego.AddTemplateExt("你文件的后缀名") + beego.AddTemplateExt("") -当你设置了自动渲染,然后在你的Controller中没有设置任何的TplNames,那么beego会自动设置你的模板文件如下: +If you enabled auto-render and you don't tell Beego which template file you are going to use in controller methods, Beego uses following format to find the template file if it exists: c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt -也就是你对应的Controller名字+请求方法名.模板后缀,也就是如果你的Controller名是`AddController`,请求方法是`POST`,默认的文件后缀是`tpl`,那么就会默认请求`/viewpath/AddController/POST.tpl`文件。 +Which is `/.