Help Anchor

Hi guys!
I’m trying to do a simple website with hugo, i used the hugo-base-theme as a start and I want that was my four links in my menu to have a anchor that link to the content in the page (like here http://gohugo.io/).
For now I just have one button who work with that line of code:
{{ if modBool $index 2 }}

{{ else }}
{{ end}}

but i don’t know why…
I find this code in an other topic:
[Foo]({{<ref “#foo” >}})
bla
bla

Foo

but where do I put that ?

Thanks for help!

The Foo thing you list there is creating a link from a content (markdown) page.

Have a look at the ref and relref template funcs:

One of these funcs are used to create the magic link above, with anchor and all.

Hi!
Thanks for the answer!
I’m a big noob in dev so I don’t quite understand the use of relref
I have to put a line like this {{< relref “blog/post.md#who” >}}{{< relref “blog/post.md#who” >}} in my post and an id in a node page ?

It’s easier to understand this by just testing it.

So given my-blog-post1.md:

# This is a title

And some text

And then my-blog-post2.md:

# This is another title

And some text. And a link [back to post1]({{< relref "my-blog-post1.md#this-is-a-title" >}})

I dont’t think you need the path (/blog), but test it.

In templates, i. e. not in content/markdown files, you will have to use the relref/ref funcs directly:

<a href='{{ relref "my-blog-post1.md#this-is-a-title" }}' ...

aaah ok I’m getting it, I thought that the variable was sort of id… I put the relref function in my html and now when I click on the link it send to the adequate content but it only display the post without css or the rest of the site. The value that it send is /post/my_post/ am I missing something ?

Well, this is kind of hard to debug without seeing the complete project, but I have a problem seeing how the link should have anything to how the target looks. That sounds like a different problem.

This is a line from my menu:

<a href='{{ relref . "location.md" }}' class="btn btn-success btn-lg" >Location</a>

The value that it return to me is /post/location/, I dont see what’s wrong…

/post/location sounds reasonable – but as I said, impossible to say without seeing the complete project.