Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
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
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
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
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.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: named anchor
jsoo wrote:
Tangentially, I don’t think the
name
attribute was ever deprecated, but I believeid
is preferred, and these days browser support forid
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., nohref
attribute). I used anh2
in my example but you could also use aspan
, 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
Offline
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
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
Pages: 1