Mediawiki link within the page to a specific place, rather than a section
Asked Answered
S

3

10

1. Question

If I code like the following, then I have a link within the page to a specific "section"

[[#SectionTitle|displayed text]]

But what if I want to have a link within the page to a place, I mean any place?

Sometimes I might want to directly refer to a part of the page that isn't at the start of a section.

2. What I tried

I tried something like this

[[#Foo|displayed text]]
{{anchor|Foo}}

This seemed to ask me to make a page Template:Anchor

So I copied the Template:Anchor page of wikipedia.

But Template:Anchor again seemed to ask to make some new page, because Template:Anchor only says

{{#invoke:anchor|main}}

So my attempt didn't work.

Sutlej answered 14/5, 2014 at 13:43 Comment(1)
link to official mediawiki help on anchors for section headers: "Section headings and the top of the page are automatically anchored"Marela
G
15

Use the following to create the anchor:

<div id="NameOfAnchorHere">optional text</div>

which can be referenced as:

[[#NameOfAnchorHere| test]]

More information about linking in MediaWiki can be found here

Glazed answered 14/5, 2014 at 13:50 Comment(2)
By the way, putting <div id="anchor1"></div> seems to cause line break. But I don't want to break line there. How can I solve this problem?Sutlej
try <div id="anchor1" style="display:inline;"></div>Glazed
T
2

And just to explain what's going on with {{#invoke:anchor|main}}: that's using Lua code in the Module namespace to generate the anchor.

Note that it eventually uses

<span id="NameOfAnchorHere">optional text</span>

which, I think, is nearly equivalent of <div style="display:inline;">, I think.

Tabithatablature answered 5/5, 2016 at 14:9 Comment(0)
F
0

Put the closing tag at the end of the paragraph, not right after the anchor. That will then not cause a line break. Or use the span tag which can be immediately after the anchor.

Fulllength answered 28/12, 2019 at 1:32 Comment(1)
Could you please write some example code? I'm also unsure why you're mentioning line breaks, because the original question asker didn't mention that. Does this answer the question?Vestige

© 2022 - 2024 — McMap. All rights reserved.