2016-05-06 15:35
浏览 290

如何从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条回答 默认 最新

  • dongqiya9552 2016-05-10 03:04

    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>
    解决 无用
    打赏 举报

相关推荐 更多相似问题