2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Beegoでテンプレート変数のフォーマットを変更する

2
Last updated at Posted at 2015-01-02

Beegoに限らないですが、JS側のテンプレート変数のフォーマットとサーバー側のテンプレート変数が一緒だと、問題があります。

しょうがないから、サーバー側のテンプレートには以下のように書いて、レンダリングされると{{ hoge }}みたいになるようなこともしていましたがさすがに面倒くさい。

{{`{{ hoge }}`}}

最近使っているGoのフレームワークのbeego(実際にはbeeageのほうを使ってますけど)で、このテンプレート変数のフォーマットを変更する方法を残しておきます。main.goのところで、変数の左右に配置するフォーマット文字列を定義してあげるだけです。

main.go
func init() {
	beego.TemplateLeft = "{{{" #左のフォーマット
	beego.TemplateRight = "}}}" #右のフォーマット
	beego.Router("/", &controllers.MainController{})
	beego.Run()
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?