Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Field in keywordContains?

I'm having problems getting the following to work:

{$ forEach x in (and (not (thisArticle)) (keywordContains "lifestyle,") (keywordContains "{$.extra1$}")) $}
<li><a href="{$x.link$}">{$x.author$}</a></li>
{$ next $}

Regardless of what I enter in the field extra1 no articles are listed.  When I hard code what I enter into extra1 in the template it works.  Am I missing something here or does this not work?

Thanks in advance for your help

Pryan
Monday, November 22, 2004

Hmm, I seem to remember having a problem like this myself where you can't use a variable of any kind in the condition section of a foreach loop.

I searched for that post, but I can't find a @*%# thing on this forum.  The scrolling off the screen works fine for discussions but sucks as a solutions archive.

As an aside, do you really want {$.extra1$} (is this code in a template), or do you want {$x.extra1$}?

Does your NOT/AND logic grouping match what you are looking for?

I would simplify this loop, first just using keywordContains to make sure it was acting as expected, then try a loop using extra1.

David Burch
Monday, November 22, 2004

Could it be something like this?

You have a page A that lists according to a criterium in its field extra1 a number of other pages (X, Y, Z) that have the content of this field extra1 as a keyword.

But in the forEach loop you are not comparing the keywords of these pages X, Y, Z with the criterium in extra1 of page A, but with the content of their own field extra1, so extra1 in pages X, Y, Z.

If these extra1 fields don't contain the same content as extra1 of page A, you will get no hits.

Ruud van Soest
Monday, November 22, 2004

Actually, I don't see any possibility to avoid hardcoding the selection criterium in this kind of conditions, where the criterium is an content element of another page. Does anyone?

Ruud van Soest
Tuesday, November 23, 2004

No, unfortunately at this point you can't use a variable as part of the condition.  It has to be a hardcoded value.

Basically you can't have a {$$} section inside another {$$} section.

Michael H. Pryor
Fog Creek Software
Tuesday, November 23, 2004

*  Recent Topics

*  Fog Creek Home