Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Bookmarking within an article

I'd like to be able to have a list of links at the top of an article that link to content on the same page, ie bookmarks. I'm trying to do a FAQ-like thing with 5 to 10 questions at the top that link to answers lower down. A "return to top" link would be nice too.

I know I can have an "index" with a script that lists headlines & links to all the articles in a folder, but I'd rather do the whole thing on one page, especially if it's a short list of Q&As.

Any help or thoughts will be appreciated!

Eric Chromick
Friday, January 04, 2002

I hope there is a better way and I'm sure you can do it in the HTML.

But, once I got the page like I wanted, I copied the HTML into FrontPage, added the bookmarks, then copied the HTML back into CityDesk.

TK
Friday, January 04, 2002

I'll assume for the example that you have all your questions in a folder called "Questions" and each question is its own article.  The headline of the article is the question (e.g. How do I cook spotted trout?) and the body is the answer (e.g. I cookthem like so...).  Put a UNIQUE identifier in each extra1 field for the articles (e.g. Trout) which will be used to make the bookmark.

Then in either an article or an html file, add these foreach loops (in the HTML view):

1. at the top to generate the list of questions...

{$foreach x in (folder "Questions")$}
<a href="#{$x.extra1}">{$x.headline$}</a><br>
{$next$}

2. at the bottom to generate the list of answers...

{$foreach x in (folder "Questions")$}
<a name="{$x.extra1$}">{$x.headline$}</a><br>
<blockquote>{$x.body$}</blockquote>
{$next$}

That's all.  Notice that the href for a bookmark has a # in front of it, and the part you want it to go to is surrounder by an <a name="bookmark"> tag.

Michael H. Pryor
Friday, January 04, 2002

I tried the scripts you suggested Michael, but got the dreaded "Script Error: illegal token or identifier "}"" error. Normally, I'd blame my fatfingering, but I cut & pasted so as not to have any typos.

I get the same result whether the scripts are in an article or html file.

This *seems* to be similar to other situations where I've had 2 scripts on a page referencing the same variables. Probably a whole different issue, but I thought I'd mention it just in case it rings a bell.

Thanks for the cut & paste idea tk, but I'm pigheaded & want a script to do it...

Eric Chromick
Friday, January 04, 2002

I forgot a $.  I knew I should have tried it before I posted it...

anyway...

1. at the top to generate the list of questions...

{$foreach x in (folder "Questions")$}
<a href="#{$x.extra1$}">{$x.headline$}</a><br>
{$next$}

2. at the bottom to generate the list of answers...

{$foreach x in (folder "Questions")$}
<a name="{$x.extra1$}">{$x.headline$}</a><br>
<blockquote>{$x.body$}</blockquote>
{$next$}

Michael H. Pryor
Friday, January 04, 2002

'Spose I could check syntax myself before I gripe about the code not working ;-)

Works like a champ in an html page, but includes itself if used in an article. I mention this only so others will know that using the script in an html page is the way to go.

Thanks a bunch!

Eric

Eric Chromick
Friday, January 04, 2002

You can use it in an article inside the folder..
Just put the keyword INDEX in the keywords field and modify the foreach loop to be

(and (folder "Questions") (not (keyword_contains "INDEX")))

Michael H. Pryor
Friday, January 04, 2002

I made a couple additions to the script that others may find handy.

1. In HTML view I put <a name="top"></a> as the first line so I could "Return to Top"

2.  I added <p>&nbsp;</p> between the scripts to give a little extra spacing between the list of questions and answers.

3. I made the .Headline bold so it stands out.

4. Added <p><a href="#top"><i>Back to Top</i></a></p> after the blockquote so you don't have to scroll back up. A personal issue on my part.

Here's my version of the script:

{$foreach x in (and (folder "Conditions") (not(keyword_contains "Index")))$}
<a href="#{$x.extra1$}">{$x.headline$}</a><br>
{$next$}
<p>&nbsp;</p>
{$foreach x in (and (folder "Conditions") (not(keyword_contains "Index")))$}
<a name="{$x.extra1$}"><b>{$x.headline$}</b></a><br>
<blockquote>{$x.body$}</blockquote>
<p><a href="#top"><i>Back to Top</i></a></p>
{$next$}

An observation on sticking scripts and text on the same page: I've found that if you create an article in Normal View and then insert the script in HTML view you're fine. However, once I switch back from HTML to Normal, my script gets mangled.

Eric Chromick
Sunday, January 13, 2002

I was wondering; because the main page is a FAQ type document with the links AND articles in the one document; is there a way to prevent CD from processing the articles in the folder that we used in the FAQ when we publish?  The extra folder of non linked to FAQ articles is easy enough deleted but I'm just wondering if there was a setting that I have overlooked that would not create this folder of articles.

Robbert de Groot
Monday, February 03, 2003

*  Recent Topics

*  Fog Creek Home