Error in go templates using if statement

In the main template I call the sub template:

<div id="nav">
      {{template "nav" ("posts")}}

In the sub template I have following if statement:

{{if eq . "posts"}}
       <a href="/posts" class="btn active"><img src="icn/post.svg"><p>test</p></a>
        <a href="/posts" class="btn"><img src="icn/post.svg"></a>

But I get an error when executing:

template: nav.html:3:5: executing “nav” at <eq . “posts”>: error calling eq: invalid type for comparison

What am I doing wrong? The argument “post” is transmitted to the sub template and visible in the sub template.


Works for me…

1 Like

Yes. It works. The problem was that I called other “nav” without arguments.

Thank You!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.