Looping Through a Widget Collection

Suppose that you have created three widgets in Graffiti CMS that you wish to display on all of your pages, with one exception.

On the home page you wish to only display two of the three widgets.  In order to accomplish this task you can get a list of the current widgets and display only two of them rather than all three.

This would look something like the following snippet of Chalk code:

#foreach($rw in $data.RightWidgets())
#if($rw.Title != “Site Options”)
$rw.Render(“<li class=’widget’>”, “<h2>”, “</h2>”, “</li>”)
#end
#end

Here we are saying loop through all of the widgets in the right sidebar, but do not render the sidebar item which has a title of “Site Options”.  That’s all there is to it!

Leave a Reply

Your email address will not be published. Required fields are marked *