Fog Creek Software
Discussion Board

Knowledge Base
Terry's Tips
Darren's Tips

ifonly keywordContains worked with if

In creating a template I was trying to do something like:

{$ if KeywordContains "homepage" $}
show this bit here
{$ endif $}

but IF only uses blank and nonblank

I want to use this because the extra fields are all in use. My thinking here is it gives the site designer the ability to turn things on and off easily across pages (assuming they can remember what all their little words meant).

For now, I think I have to settle for creating another template

Friday, November 21, 2003

try this....

{$ foreach x (keywordcontains "homepage") $}
{$ after $}
do your stuff here
{$ next $}

A thousand pardons if the syntax isn't exactly right.  I don't have CD installed here at my office.  Basically this tests to see if the keyword has homepage in it.  If it does, then only once (after) does it do your stuff.  You may need additional conditions to limit to folders, etc.

I use this a lot....

Jeff Kolker
Friday, November 21, 2003

Thanks Jeff.

But that only works if the script appears in an article though not inside a template. Is that where you're using the for loop?

If any page contains "homepage" (doesn't matter if I limit the pages checked), the code turns up in all pages.

Friday, November 21, 2003

I use it in templates, and articles.  I tend to group like documents in their own subfolders, which helps on some of the loops.

You may just have to play with it some.... various (folder) or (filename) conditions may help. 

I'm like you and try to keep everything in one template.  My website at has some of my suggested scripting and uses only one template, but it may not be exactly the same thing you are trying to do...

Jeff Kolker
Friday, November 21, 2003

Just figured it out - the actual script I am using is:

{$ forEach x in (and(thisArticle)(keywordContains "homepage")) $}
    the bits that I want to show

Friday, November 28, 2003

*  Recent Topics

*  Fog Creek Home