Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

thisArticle

How do you script something like this:

If Not(ThisArticle="Index") Then
  ... include a snippet of something
End If

In CityScript?

I want to include a "back" link in a template, but I don't want it to show up on the home page.

Thanks

CRC
Saturday, August 02, 2003

Create a new template, call it Index, and copy over the entire other template to it. Then, set the Index article's template to the Index template. Got all that? ;-)

Israel Orange
Saturday, August 02, 2003

Natch, all the other articles keep using their original template.

Israel Orange
Saturday, August 02, 2003

No offense, but that seems rather kludgy. Isn't there a way to do that with some code?

CRC
Saturday, August 02, 2003

None taken, it is kludgey. I haven't a clue how else. You might try comparing the .Headline field with the actual headline of the site?

Israel Orange
Saturday, August 02, 2003

I got it! Put a keyword in Index such as "nobacklinks", and inside your foreach loop:
{$ if not(keywordContains "nobacklinks") $}
I probably got something wrong syntactically there but you get the idea. If you are using an old version use keyword_contains instead.

Israel Orange
Saturday, August 02, 2003

Check out the CD help file under:

"Linking to Previous and Next Articles"

topic.  I think it does just what you need

Joel Goldstick
Saturday, August 02, 2003

Israel, I think you're onto something, but I can't seem to get the script to work.

As for the back link itself, I was going to put in a simple javascript snippet like this:

<a href="#" onClick="javascript:history.go(-1);"
onmousemove="status='Click here to go back to the previous page';"onmouseout="status='';">Back</a>

I don't really want to to go to the next or previous article in a folder.

Thanks

CRC
Saturday, August 02, 2003

Israel's suggestion would be good, except for one huge problem: you can't use If with anything other than 'blank' and 'nonblank'. :/

Martha
Monday, August 04, 2003

As far as your original question, why do you want to duplicate basic browser functionality? Every browser out there has a Back button, there's no need to put another one on your pages. Put a link to the home page, by all means (I hate it when I get to a page via search engine, but find it a dead end as far as site navigation is concerned); but if the user merely wants to get back to the last page he visited, he's gonna click his browser's Back button regardless of how many duplicates you provide (because he's learned through bitter experience that website-provide 'back' links are unreliable).

Martha
Monday, August 04, 2003

Excellent point Martha-no need to (poorly) duplicate a browser button!

Israel Orange
Monday, August 04, 2003

Well, I'm kinda lazy, see, and it takes a lot of effort to move my mouse back up to the top of the window to hit that little button. ;-)

CRC
Monday, August 04, 2003

I'm still having some difficulty figuring out how to use the scripting language effectively.

How do you do basic "if" functionality? Everytime I try to say something like...

If (condition)
  do something
else
  do something else

...CD pukes. Can someone tell me how to script

{$ if keywordContains("someword") $}
    [include some really cool feature here]
{$endif $}

please?

CRC
Monday, August 04, 2003

you can't do "if keywordcontains then"; you have to do "foreach x in keywordcontains" instead. Also, there is no else clause. As Martha pointed out "if" only works for blank and nonblank, nonblank being the else clause. So if you want to have both, you have two loops, one testing blank, and one testing for nonblank.

Israel Orange
Monday, August 04, 2003

I guess I'm just too hard-headed. I can't seem to get a grip on this language. I've been a programmer for years, yet for some reason I'm drawing a blank here.

Why would I write a loop just to test the equality of a condition? I just want to include some HTML code if an article contains a certain keyword. I can't make it work.

Please have patience with me, master.

CRC
Monday, August 04, 2003

Well, I've been programming for years too, and CityScript is often beyond me. I always have to look up how things work, and I find it totally unintuitive despite how English-like it is.
Maybe I'm just thick-headed. Or maybe Joel should write an article, "What to unlearn to use CityScript effectively" or "CityScript for programmers" ;-)

Israel Orange
Monday, August 04, 2003

Ha ha! I'm glad I'm not the only one who feels that way!

That would be a great article..."CityScript for Programmers". I think a more robust scripting language would make the killer app of the year!

CRC
Monday, August 04, 2003

I meant to say "A more robust scripting language would make CityDesk the killer app of the year".

CRC
Monday, August 04, 2003

The "if" clause appears to be a single purpose syntax: Testing for blank or nonblank. It can't appear anywhere else. Somebody correct me if I'm wrong.
Checxk this out, actual code I'musing that works:
{$foreach x in (and (folder "newsitems")(keywordContains "keeponindex"))$}
{$ .StartBlock $}{$x.teaser$}{$ .EndBlock $}
{$next$}
{$foreach 14 x in (folder "newsitems")sortdescendby .fileddate$}
{$ if nonblank x.body $}
{$ .StartBlock $}<p><a href="{$x.link$}">{$x.headline$}</a><br /><font size="1">{$ setDateTimeFormat "English" "MM/dd/yy" "hh:mm" $} {$x.filedDate$} </font></p>
<blockquote>{$x.teaser$}<a href="{$x.link$}"> Read more...</a></blockquote>{$ .EndBlock $}
{$endif$}
{$ if blank x.body $}
{$ .StartBlock $}<p>{$x.headline$}<br /><font size="1">{$ setDateTimeFormat "English" "MM/dd/yy" "hh:mm" $} {$x.filedDate$} </font></p>
<blockquote>{$x.teaser$}</blockquote>{$ .EndBlock $}
{$endif$}
{$next$}
Do you see what I mean about, -how to use keywordcontains in a loop and -how to test blank/nonblank in a loop? If not I'll try to explain some more, I'm not even sure if I'm actually answering your question or not...

Israel Orange
Monday, August 04, 2003

IO and CRC, I think it all comes down to "you can't nest foreach's in CityScript" at least not yet. So if you are looping though a folder and want to do something special to certain articles in the folder, I think the best you can do is some isblank stuff.

There are a huge number of posts about it. I'm sure the Fog folks have it on their list. Joel has made some tanlilizing hints about the future of CityScript.  Some folks have used javascript to get it done.

tk
Monday, August 04, 2003

PS some explanation of above:
-This appears in my index page.
-"keeponindex" is a keyword I use to keep articles' teasers on the index page regardless of whether they are among the last 14 articles published or not.
- .StartBlock and .EndBlock are my own variables; they refer to a CSS "<div id="whathaveyou">" and "</div>" respectively.
-Note in the second loop that I test for the nonblank condition once, then the blank condition, then loop. This is more logical than what I said before about looping twice...

Israel Orange
Monday, August 04, 2003

Thanks, Israel. I'm going to copy your code and pull it apart and see how it works. I think the part I was missing was the and(folder="") part.

CRC
Monday, August 04, 2003

tk, where could I find those tantalizing hints? Are they buried in the posts or did he write an article about it?

Thanks!!

CRC
Monday, August 04, 2003

The hint was either here in the forum or on in joelonsoftware. The gist of it seemed to aim CityScript toward Javascript rather than towards some other scripting languages. That's about as far as it went. No hints on if, when, or how.

Joel's basic message is that folks should pick the product that meets their requirements right now and he hopes it's CityDesk. But folks shouldn't choose CityDesk based on some anticipated feature, because Fog won't make promises about features.

Nonetheless we're all waiting on those un-promised features and we're making do until ...

As for me, I'm hoping that CityScript will not leave me behind as it improves. Simple is about as much as I can usually handle.

tk
Monday, August 04, 2003

*  Recent Topics

*  Fog Creek Home