Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-08-24 13:18:50

Batch108
New Member
From: Etwall Derby
Registered: 2009-07-15
Posts: 7
Website

named anchor

I’m new to TextPattern and have been using DreamWeaver CS4, I am wanting to create a named anchor on my pages so that the end user can jump to various places within the page. What is the TXP code, and what is the format?

Offline

#2 2009-08-24 13:56:10

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: named anchor

If you want to do this within an article, and if you are using Textile for that article, you can assign an id to an element with the (#id) notation:

h2(#foo). Header

gives

<h2 id="foo">Header</h2>

You can then link to it using Textile’s link format:

Some text with a "link":#foo

gives

Some text with a <a href="#foo">link</a>

However, if you want to do this in a page, you’ll have to write out the HTML in full.

Is that what you meant?


Code is topiary

Offline

#3 2009-08-24 14:07:47

Batch108
New Member
From: Etwall Derby
Registered: 2009-07-15
Posts: 7
Website

Re: named anchor

Hi sorry for being dense!

We have a page with the words General Programme which is a link and has the following HTML code <a href=”#gp”>General Programme</a> which then goes to the text General Programme with the HTML code <a name=“gp” id=“gp”></a>

it’s been a hard day; my brain is a bit frazzled, does this make sense, I have used Textile a while back where I used #gp which went to the appropriate text with the code (#gp),

is this clearer, probably very simple; but not today.

Offline

#4 2009-08-24 15:42:23

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: named anchor

Tangentially, I don’t think the name attribute was ever deprecated, but I believe id is preferred, and these days browser support for id is no longer an issue. That is, <a id="gp">General Programme</a> should be all you need for the anchor. I don’t think you can do this in Textile — make a non-linking anchor (i.e., no href attribute). I used an h2 in my example but you could also use a span, like this: %(#gp)General Programme%

Txp has a particular meaning for “page” (it’s a template, really), which is why I asked if you meant this to be part of a Txp article or page. In an article you can use Textile, but not in a page.

In either case you can always write out the HTML in full.


Code is topiary

Offline

#5 2009-08-24 23:02:59

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: named anchor

jsoo wrote:

However, if you want to do this in a page, you’ll have to write out the HTML in full.

Like so


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2009-08-25 13:40:17

Batch108
New Member
From: Etwall Derby
Registered: 2009-07-15
Posts: 7
Website

Re: named anchor

jsoo wrote:

Tangentially, I don’t think the name attribute was ever deprecated, but I believe id is preferred, and these days browser support for id is no longer an issue. That is, <a id="gp">General Programme</a> should be all you need for the anchor. I don’t think you can do this in Textile — make a non-linking anchor (i.e., no href attribute). I used an h2 in my example but you could also use a span, like this: %(#gp)General Programme%

Txp has a particular meaning for “page” (it’s a template, really), which is why I asked if you meant this to be part of a Txp article or page. In an article you can use Textile, but not in a page.

In either case you can always write out the HTML in full.

Thanks for the feedback, I’m struggling to edit the HTML. When I go into Advanced properties and use Textile to show the HTML, when I change one of the words to <a id=“gp”>General Programme</a> and save the article the article doesn’t show the link? What am I doing wrong?

Offline

#7 2009-08-25 13:41:51

Batch108
New Member
From: Etwall Derby
Registered: 2009-07-15
Posts: 7
Website

Re: named anchor

uli wrote:

jsoo wrote:

However, if you want to do this in a page, you’ll have to write out the HTML in full.

Like so

Thanks for the feedback; the link doesn’t work?

Offline

#8 2009-08-25 16:56:20

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: named anchor

Batch108 wrote:

Thanks for the feedback, I’m struggling to edit the HTML. When I go into Advanced properties and use Textile to show the HTML, when I change one of the words to <a id=“gp”>General Programme</a> and save the article the article doesn’t show the link? What am I doing wrong?

<a id="gp">General Programme</a> is an anchor but not a link, because there is no href attribute (i.e., a URL to link to). From your mention of Advanced properties I gather you are indeed working in an article. Note the vertical tabs along the right-hand side of the body text input box. The HTML tab gives you a preview of the actual HTML output that Txp will produce for this article body. If you put <a id="gp">General Programme</a> into the article body and then click the HTML tab, you should see that the code is preserved (it might get wrapped into a paragraph, depending on exactly how you have entered it). You should see the same thing if you save the article and then view the HTML source of the article on the front-end website. If you have added a link such as <a href="#gp">General Programme</a> elsewhere on the page, it should link to the anchor. If this is not what you are getting, you may get more effective help from this forum if you post a tag trace.


Code is topiary

Offline

#9 2009-08-25 18:14:34

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: named anchor

Batch108 wrote:

Thanks for the feedback; the link doesn’t work?

Certainly does, but unfortunately archive can not be viewed by new members nor non-registered.

Offline

#10 2009-08-25 20:35:36

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: named anchor

Batch108 wrote

the link doesn’t work?

Alright, I just paste-post Mary’s proposal here.

Mary wrote:

First, go to your article form (most likely “default”), and add an id to each article:

<h3 id="article-<txp:article_id />"><txp:title /> · <txp:posted /> by <txp:author /></h3>

<txp:body />

Next, create a new article form (“list”):

<li><a href="#article-<txp:article_id />"><txp:title /></a></li>

Finally, in your page, call your article list twice:

<ul>
<txp:article form="list" />
</ul>

<txp:article form="default" />

All done. :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

Board footer

Powered by FluxBB