Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Using variables or fields in keyword_contains

Is there a way to use a variable or a field instead of the fixed string "foo" for the condition in:
  {$ foreach x in(keyword_contains "foo")$}

I want to create a single template that can pick the keyword to use from the $.extra2$ field, but the publish process seems to insist on condition being hard coded.

The alternative is that I'm stuck with having to create multiple templates and hardcode the "keyword" in each keyword_contains condition.

Jason Buck
Friday, July 25, 2003

Why not use the keywords field to contain the keywords?  I think TK has some articles and posts on keywords at his site (see Terry's Tips link on the left

Joel Goldstick
Friday, July 25, 2003

maybe I didn't explain my problem too well (It is Friday!)

The problem I have is that the foreach x in(keyword_contains "foo") expression in my template seems to need the keyword value "foo" as a string. I want to be able to pass a value from another field (extra2). This means that if I have an article with "foo2" in the $.extra2$ field I want the article to generate a list of all articles with "foo2" keywords. If I have another article (using the same template) with "foo3" in the $.extra2$ field I want the article to generate a list of all articles with "foo3" keywords.

Jason Buck
Friday, July 25, 2003

Unfortunately this doesn't work. It would enhance the
flexibility of cityscript a lot if it did. You can place the entire foreach loop in a variable then put the variable in extra2.

That is create a variable named say, linksfoo that contains

{$ foreach x in(keyword_contains "foo")$}
<a href="{$ x.link $}">{ $x.headline $}</a>
{$ next $}

another that does the same thing for "foo2" etc.

Ken McKinney
Friday, July 25, 2003

*  Recent Topics

*  Fog Creek Home