2017-05-12 17:43


  • revel
  • templates

After creating multple endpoints customizing footer.html, I end up with this error for not apparent this don't effect the functionally of the application, just annoying me. Tried:

  revel run revel_app or dev

Revel Template Execution Error

: executing "footer.html" at : error calling eq: invalid type for comparison.

  {{if eq .RunMode "dev"}}

  {{template "debug.html" .}}


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douao1858 douao1858 4年前

    The error you see arises when one of the arguments to eq is either undefined in the current context or is not of a "basic type" (see the last paragraph of this section)

    So assuming that footer.html is a "pratial" template that is associated with other templates which invoke the footer template using the template action you need to ensure that the context passed in to the template invocation contains the .RunMode value and that the value is of a basic type.

    点赞 评论 复制链接分享
  • dongwen5870 dongwen5870 3年前

    While this question seems to be answered there is plenty missing. First the question is incomplete... WHAT IS THE ERROR? My guess us that the .RunMode is missing when the template parser/executor was run. There are not best practices for golang templates, however, this is a common problem when overloading templates and not maintaining a dictionary of variables.

    One strategy I tend to deploy is:

    {{if eq (or .RunMode "default") "dev"}}

    This way if .RunMode is NOT assigned a value (nil exception) or an empty string then the eq uses the "default" value instead. Think of this as a shorthand like in 'C'

    This is an exaggerated example.

    a := runmode!=null?runmode:default
    点赞 评论 复制链接分享