Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

if-then-else

Someone may have mentioned this in an earlier thread without me noticing, but I’ve often missed the ability to do this in CityScript in a single article: ”if keywordContains ”something” then (some html or text) … else … (some other html or text)”

I have found that this works:
{$ ForEach x in (and(thisArticle)(keywordContains "(yourKeyword)"))$}
<any html or text>>
{$ else $}
<any html or text>
{$ next $}

An artificial “if-then-else”.

I use this to highlight various items in the main menu. Each article carries a keyword telling which main group it belongs to (no matter which folder it resides in). When an article is loaded its group is highlighted (change of background color in a table cell) in the main menu so users know where they are.

Jørgen

Jorgen B.
Friday, June 25, 2004

Good one, Jorgen!

Darren Collins
Sunday, June 27, 2004

Would it process quicker if you used "1x" instead of just "x"?

{$ ForEach 1x in (and(thisArticle)(keywordContains "(yourKeyword)"))$}
<any html or text>>
{$ else $}
<any html or text>
{$ next $}

Just wondering...

David Watts
Monday, June 28, 2004

I tried that in a template with 7 consecutive “if-then-else”, but couldn’t measure any difference in process time. I believe that CD handles forEach loops in such a way that x and 1x will result in the same amount of loops if you are working in “thisArticle”.

Jorgen B.
Monday, June 28, 2004

This should be added to the knowledge base before the topic scrolls past and it is lost (search doesn't really, here).

David Burch
Monday, June 28, 2004

Does this only work for keywordContains?  How about (folder "the/folder/path/*")?

me
Tuesday, June 29, 2004

Jørgen,  would you show us your pre-publish HTML?

Did you generate your menu (with the "foreach this article") with a CityScript?

And thanks for the tip. It's here:
http://tk-jk.net/city/Articles/fog0000000006.html

tk
Tuesday, June 29, 2004

Terry, yes as soon as it is ready.

Nothing but CityScript anywhere.

Jorgen B.
Wednesday, June 30, 2004

Before this subject scrolls off, here is a code snippet:

<table cellspacing="1" cellpadding="4" border="0" bgcolor="some color">
<tr>
{$ ForEach x in (and(thisArticle)(keywordContains "(your keyword)"))$}
<td bgcolor="some color 1" class="small" align="center">
<a href="PTMFOG0000000035">Dansk</a></td>
{$ else $}
<td bgcolor="Some color 2" class="small" align="center">
<a href="PTMFOG0000000035">Dansk</a></td>
{$ next $}

{$ ForEach x in (and(thisArticle) (keywordContains "(another keyword)"))$}
<td bgcolor="some color 1" class="small" align="center">
<a href="PTMFOG0000000034">Engelsk</a></td>
{$ else $}
<td bgcolor="some color 2" class="small" align="center">
<a href="PTMFOG0000000034">Engelsk</a></td>
{$ next $}
... and so on as many times you need
</tr></table>

As soon as the site is ready I'll post a link in a new thread.

Jorgen B.
Tuesday, July 13, 2004

*  Recent Topics

*  Fog Creek Home