Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

leaving 'thisarticle' unlinked in a loop?

Is there a simple way for me to generate a list of links that doesn't link the current article, but still prints its title?

ie, I can use 'not(thisarticle)' in a loop to keep an article out of the list, but I still want it to show up -- just not as a link.

to illustrate, i'd like something like:

*link to article 1
*link to article 2
article 3 title (current article, therefore not a link)
*link to article 4
*link to article 5
etc.

hopefully there's just something really simple that I'm missing here.

g
Tuesday, November 30, 2004

Here is one way of achieving it:

<p>Article List</p>

{$foreach x in (all) $}
    <span id="{$x.fileName$}"><a href="{$x.link$}">{$x.headline$}</a></span><span id="{$x.fileName$}2" style="display:none;">{$x.headline$}</span><br>
{$next$}

{$foreach x in (thisArticle) $}
    <script type="text/javascript">
    <!--
    document.getElementById('{$x.fileName$}').style.display = 'none';
    document.getElementById('{$x.fileName$}2').style.display = 'inline';
    --></script>
{$next$}

Regards

Patrick Thomas
http://www.citydeskwizards.com

Patrick Thomas
Tuesday, November 30, 2004

We can simplify that...we don't need the second loop:

<script type="text/javascript">
<!--
document.getElementById('{$.fileName$}').style.display = 'none';
document.getElementById('{$.fileName$}2').style.display = 'inline';
--></script>

...is sufficient.

Patrick

Patrick Thomas
Wednesday, December 01, 2004

What about the javascript: I understand that it can be made unavailable by a user, is that really a problem or is it only a marginal problem, something not to bother about too much?

Ruud van Soest
Wednesday, December 01, 2004

Not again! Just joking :-)

If javascript is turned off, all items will have a link (the current page -> to itself).

Patrick

Patrick Thomas
Wednesday, December 01, 2004

thanks much for the response -- while I'd hoped for a solution that didn't require scripting outside of citydesk, I'm glad that I wasn't blindly overlooking something obvious...  :)

Still, if there's anything that CD3 should have, it should be a vastly expanded "CityScript,"  including the ability to do simple things like selecting articles based on their relation to the current one.

One would expect to have the ability to 'pick the previous 10 articles,' or 'pick all articles following this one'  (among a bunch of other things).

g
Saturday, December 04, 2004

Although I didn't try it in real world, since I'm re-discovering CD for a short time, I wonder if this could solve your problem:

{$ previousLink x in (thisFolder) sortdescendby ..... $}
<a href={$x.link}>{$ x.headline $}</a>
{$ end $}

{$ .headline $}


{$ nextLink y in (thisFolder) sortdescendby ... $}
<a href={$y.link}>{$ y.headline $}</a>
{$ end $}

in this page,

http://www.fogcreek.com/CityDesk/2.0/help/Scripting_With_CityScript/LinkingtoPreviousandNextA.html

they say that  "n is an optional number, greater than zero, indicating the maximum number of articles that you want included in the sequence. If omitted, all articles that match condition are included in the sequence". so if I understand well, you can list all the articles before the one you're in, if they belong to the same folder or match another set of conditions.

I haven't tried if it works effectively, w/o bug. but if it works, it's really simple and doesn't require anything  but cityscript.

brandt
Tuesday, December 07, 2004

oops, I've forgotten the "" in the <a href="..."> above.

brandt
Tuesday, December 07, 2004

I'm pretty sure the above won't work. According to the linked help page:

"You can think of them [nextLink and previousLink] as a variety of forEach that magically includes only one article, the next one or the previous one, as offset from the current article."

Instead of showing all articles before and after the current one, you'll only see the one article immediately before and the one article immediately after the current one.

Darren Collins
Tuesday, December 07, 2004

*  Recent Topics

*  Fog Creek Home