如何从beego AppConfig获取值并将其呈现在HTML模板中?

I want to get value of a key defined in beego's app.conf and render in html pages. As per documentation on http://beego.me/docs/mvc/view/template.md I can get value of AppConfig by using config function in templates. However there is no example in documentation.

Get the value of AppConfig. {{config configType configKey defaultValue}}. configType must be String, Bool, Int, Int64, Float, or DIY

After trying many ways I came to this:

<div>{{config config.String config.appname "TestDefaultValue"}}</div>

But I am always getting error:

<config>: wrong number of args for config: want 3 got 0

What is the correct way to use config template function?

1个回答

Finally I solved this myself. config template function accepts all parameters as string.

Correct way to use config template function is:

<div>{{config "String" "appname" "TestDefaultValue"}}</div>
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐