ComicCMS User Manual


Template Structures :: The Foreach Structure

We already know that templates link to items (e.g. a comic), that's how we can use {{comic_*}} variables. But wouldn't it be great if we could show more than one item on a page? Like, a list of comics, like an archive or something. <ul>
That example will print the title of every comic linked to the template. As you may well guess everything between {{foreach:comic}} and {{endeach:comic}} is repeated for each comic there is. Simple stuff.

Now here's a gem. As you may know news posts link to the comics they were posted around the same time as. So wouldn't it be nice to be able to list all the news posts attached to the comic you're looking at? {{foreach:comic_news}}
Bam! That's everything you've ever dreamed of right there. Be aware though: You can only use {{news_*}} variables between the {{foreach}} and {{endeach}}, not anywhere around the template as that is still linked to a comic.

If you are looking at a comic then you can also use {{foreach:comic_tag}} which goes through for each tag the comic owns, the only variable here is {{tag}}.

ComicCMS, free php webcomic management software Copyright © 2007 Steve H