Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Iterating with Include

I have a folder that contains FAQ's that I want to stitch together.

Can I to something like this?

{$ foreach x in (and folder "/somefolder" $}
    {$ include "{$ x.somevariable $}" $}<br />
{$ next $}

_
Tuesday, August 31, 2004

You can do this:

{$ foreach x in (folder "/somefolder") $}
    {$ include "{$ x.somefield $}" $}<br />
{$ next $}

where somefield is one of these: .headline, .author, .teaser, .sidebar, .about, .extra1, or .extra2.  Note: these fields are still referenced this way in CityScript even if you rename their labels in the template properties.

David Burch
Tuesday, August 31, 2004

Now, I should have read that closer.  I don't think you can use the include portion.  Sorry for being too quick on the draw.

David Burch
Tuesday, August 31, 2004

Okay, I went off to try it to see if you could do it and here's what I found.

Situation: I have an articles folder containing three articles.  I have a snippets folder full of articles containing stuff I want to reuse.  One of the articles in the snippets folder is named CostOfTeaInChina and contains the text $4.

I can do two things:
1.
{$ foreach x in (folder "/articles") $}
    {$ include "/snippets/CostOfTeaInChina" $}<br />
{$ next $}

or

2.
{$ foreach x in (folder "/articles") $}
    {$ .Snippets$}<br />
{$ next $}

Where the Snippets variable contains the exact include of case 1.

When it is run I get this:
$4<br />
$4<br />
$4<br />

So, the include is included once for each iteration of the loop.  Does that answer your question?

David Burch
Tuesday, August 31, 2004

Thanks for the effort!

I want the loop to include only one copy of each article in a folder.  That's why I chose {$ Include $}.  This way I can stitch together 'How To's' as well as use the individual FAQ's discretely with no duplication.

The search continues.

_
Wednesday, September 01, 2004

Can you explain your current setup with examples of what you are trying to do?

David Burch
Wednesday, September 01, 2004

I've got a folder of FAQ articles that are referenced from within the site.

I also have a Tutorial that is constituted from these FAQ's.  So what I do is reference the FAQ articles in the order that I want and I have a 'Super' Article, if you will.

These FAQ's are currently hardcoded as well as linked at the top of the page in a TOC.

I'm trying to eliminate the need to hard code them by putting in a loop that uses the include. (See Code Above)  Eliminates 90% of the code and can be re-used.

The problem I'm having is that I can't manage to sort out the string portion of the include.

There may not be a way?!?

Thanks Again

_
Wednesday, September 01, 2004

Does this do what you want?

{$ foreach x in (folder "/articles") $}
    {$ x.body $}<br />
{$ next $}

Ken McKinney
Wednesday, September 01, 2004

Friggin' rookies... I'm a putz!

Thanks Ken

_
Wednesday, September 01, 2004

I think the 'include' statement threw you off. It's really meant to be used to include the body of a single article, kind of a shorthand version of a 'foreach 1x...' loop.

Darren Collins
Wednesday, September 01, 2004

Very generous of you but it could also be that I'm a slow coach <g>

_
Thursday, September 02, 2004

*  Recent Topics

*  Fog Creek Home