Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

if..in [foldername] only

A CD newbie here. I want a link to appear on pages that are in a specific folder and not on other pages that use the same template.

Can't find an example of how to script this. Any suggestions? Also, is there any place where there are examples of scripting that gets into more detail than the online help?

I hope this is the right place to post questions like this - pls tell me where if not.

Also, when willl thisfolder work with next/previous? And yeah, lose the <p> tags! : )

Chas

ChasInNapa
Tuesday, May 27, 2003

The link can be made with keywords in the files in the folder where you want the link to appear.

{$foreach x in (and(folder "YourFolderName")(keyword_contains "(YourKeyword)"))$} <A href="{$x.link$}">{$x.headline$}</A>
{$next$}

Jorgen Brenting
Tuesday, May 27, 2003

In CityDesk 2 only...

{$ foreach 1 a in (and (folder "MyFolder") (thisFolder)) $}
This text will only appear in articles in "MyFolder"
{$ next $}

where MyFolder is the name of your folder.

How it works: the condition lists all articles that are both in MyFolder *and* in the current article's folder. That means, if the current article is in MyFolder, the list enumerates all articles in the folder. If the current folder is not in MyFolder, the list returns nothing. I put a "1" in the forEach clause so it only runs through the loop at most once, no matter how many articles there are. And the body of the loop happens to include only plain text, no CityScript, which doesn't bother anyone.

Good sources of CityScript tips and tricks can be found in the "other resources" section of the margin of www.citydesknews.com - especially http://tk-jk.net/city/index.html

Joel Spolsky
Tuesday, May 27, 2003

This works perfectly, Joel (not really a suprise :)

What I am doing is adding a Back to Index link for a folder of news item pages, so I want to go one step futher - I also want to exclude the index page which is in the same folder, as it makes no sense for it to have a link to itself.

So I want blend the two suggestions into something like

{$ foreach 1 a in (and (folder "MyFolder") (thisFolder) (keyword_contains "(newsitem)")) $}
This link will only appear in articles in "MyFolder" and not on the index page
{$ next $}

...which doesn't work. Is it even legit to have three conditions like this??

Better still, I'd prefer to have a NOT clause to exclude the index page rather than have to use a keyword to include every news story, which an editor might forget to do.

(I realize that the text display placeholder not really a link in the example above)

Thanks for any help...

Chas

ChasInNapa
Wednesday, May 28, 2003

Hi Chas,

How about this:

{$ foreach 1 a in (and (folder "MyFolder") (thisFolder) not(fileName "index")) $}
This link will only appear in articles in "MyFolder" and not on the index page
{$ next $}

This assumes that your index pages are always named as such.

Otherwise you'll need to use your keyword method, but put a "not" in front of it and maybe use a specific keyword for index pages.

Regards,

Ian

www.ianmjones.net
Thursday, May 29, 2003

Oops, I screwed up.

On further reflection, what you're wanting to do is say "is the current article in this particular folder, if so, do some stuff.".
Then, when you do some stuff, you need to say "is the current artcle the index, if so, don't actually do the stuff.".

So, how about:

{$ foreach 1 a in (and (folder "MyFolder") (thisFolder)) $}
    {$ if nonBlank .keywords $}This link will only appear in articles in "MyFolder" and not on the index page{$ endIf $}
{$ next $}

It's the usage of the "if" that's important, and you could alter it to your likeing, i.e. use {$ blank .keywords $} if you don't use the keyword field for index pages but do for your main articles.

If you always have keywords in your index and articles, then maybe use another field, e.g. the body.
If the index body is blank because the index article uses a template that auto-generates it's content ffrom the index's current folder, then this would be better:

{$ foreach 1 a in (and (folder "MyFolder") (thisFolder)) $}
    {$ if blank .body $}This link will only appear in articles in "MyFolder" and not on the index page{$ endIf $}
{$ next $}

And just to confuse you even further, how about this:

{$ foreach 1 a in (and (folder "MyFolder") (thisFolder)) $}
    {$ foreach 1 b in (and (not(fileName "index")) (thisArticle)) $}
        This link will only appear in articles in "MyFolder" and not on the index page
    {$ next $}
{$ next $}

In this one I've deduced that we're in the right folder, and then deduced that we're not processing the index page.

Sorry for the earlier rubbish, I hope this is better!

Ian

www.ianmjones.net
Thursday, May 29, 2003

Hi,
what if you have a structure;
Site folder
              Subfolder 1
                              index
                              Summary
                              Detail
                              Subfolder 2
                                              index
                                              Summary
                                              Detail
                                              Subfolder 3
                                                              index
                                                              Summary
                                                              Detail
              Subfolder 5 etc
index

How do I include only the Headlines of the direct child folders (Contained in 'index') in the parent index article as links? For example, 'subfolder 1' would automatically have a link to the 'Subfolder 2'  index article but not 'Subfolder 3' or any 'Summary' or 'Detail' articles.
The structure is regular in that it doesn't go beyond this number of levels but the subfolders (index headlines) are all different.

Thanks, different Ian

Ian Smith
Tuesday, June 17, 2003

*  Recent Topics

*  Fog Creek Home