Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Putting foreach loops into variables

Hi,

As per your response to Wayne Earl, I wanted to put some common HTML into a variable and then to include it in a sidebar.

Do you have an example of how this can be done as I keep getting the foreach text appearing in the sidebar rather than the results of the loop. This works if I put the loop directly into the Sidebar, but not if I go through a variable.

Best Regards,

Neil Attard

p.s. I still have a problem with the folders / articles with the same names - please see my latest response to that recent thread.

Neil Attard
Friday, November 30, 2001

Neil,

Due to the way CityScript is parsed, putting script into variables will only work if the variable is included in a file or a template, not an article.  This has to do with the understanding that in most cases script shouldn't be in an article, but instead should be included in the template.

Tell us more about what you are trying to accomplish and I'm sure we can figure out how to get this to work for you.

Thanks for the report on the same article/same folder situation - I think that for what you are trying to do, everything might work if instead of making an article with the same name of the folder, you just made an html file (named index.html) at the same level of the folder and put the code into there.

Michael Pryor
Friday, November 30, 2001

Michael,

Thanks for the reply.

For the article / folder name problem - it's no problem, I will just create a folder with a different name. I just wanted to make sure you could see the problem too.

For the variable, what I am trying to do is to have a sidebar for each article in a folder which links to all of the other article in the same folder. If it also links to itself for the moment, that's OK. For convenience, it would be good to put this into a variable, so that it I only have one place to change it later. Or perhaps I could do it with a different template for the articles in that folder?

Best Regards,

Neil Attard

Neil Attard
Friday, November 30, 2001

Neil,

I think your best bet is to create a template for each folder then, and put the foreach loop where you have {$.sidebar$} right now.

Of course, this means you'll have to cut and paste the template for each folder you want to do this in, but then again, if you did it the original way, you'd have to make sure that you always paste the variable name in the sidebar of every article.  So its basically 6 one way, a 1/2 dozen the other...

Two reasons why I think putting the foreach loop in the template is better:
1) It doesn't require the content creator (the author of the article) to have to remember to type {$.variable$} in every sidebar - they only have to remember which template to choose (and would be simple if the template was name "FolderNameTemplate").  Of course if you are using CityDesk as both the content creator AND the site designer, then you have to do the work either way.  But if you were going to pass your site off to a non-html person, its better for them not to be typing variables into the sidebar.
2) If you are going to have a lot of articles in the folder, then the amount of work will be less, since there will be no additional work (typing) you need to do in order to add a new article.

Michael Pryor
Friday, November 30, 2001

*  Recent Topics

*  Fog Creek Home