Well, sure, I can give it a try.
The normal {cycle} tag allows you to cycle through a bunch of printed values. You just need to specify the values, which can be anything at all. For instance, if you wanted to print "even" or "odd" for each entry, you could easily do it like this:
Code: Select all
{foreach from='$entries' item='dategroup'}
<div class="even_odd">{cycle values='odd,even'}</div>
<!-- Other entries stuff -->
{/foreach}
Notice that {cycle} starts over at the beginning when it runs out of values, so if we printed five entries, they'd say odd, even, odd, even, odd.
If you had a music blog, you might want to print a whole note, half note, quarter note, and eighth note for each entry in order. No problem:
Code: Select all
{foreach from='$entries' item='dategroup'}
<div class="serendipity_entries">
<img src="{cycle values='wholenote,halfnote,quarternote,eigthnote'}.gif" />
<!-- other entry stuff -->
</div>
{/foreach}
Note that {cycle} just prints out the next entry in the cycle. So if those weren't all .gif files, you could actually specify them with values='wholenote.gif,halfnote.jpg,quarternote.png,eigthnote.mng' or whatever else you had.
{cycle} is most often used in CSS styles. If you wanted to alternate colors, you could use this:
Code: Select all
{foreach from='$entries' item='dategroup'}
<div style="background: {cycle values='white,black'};">
<!-- other entry stuff -->
</div>
{/foreach}
The problem with that little loop is that we need some really interesting text color to show up on both white and black. Another cycle would do the job, right? Maybe; since we didn't name it, it's automatically named "default". That gives us this:
Code: Select all
{foreach from='$entries' item='dategroup'}
<div style="background: {cycle name='bgcolor' values='white,black'}; color: {cycle name='textcolor' values='black,white'};">
<!-- Other entry stuff -->
</div>
{/foreach}
Of course, you don't normally want 'style=' attributes in your template. You'd rather say class="{cycle values='class1,class2'}" instead.
{cycle} has lots of other options, too. For instance, you may find yourself respecifying the same color in multiple locations. In that case, you could just tell the cycle not to advance by adding advance=false. (Unfortunately, you must specify the same values every time.)
In my case, I wanted to store the value of the cycle in a variable, and not print it out. So I used assign='name', which assigns the value of the cycle to a variable, and print=false, which tells Smarty not to print the value of the cycle. Once it was assigned to a variable, I could check it with {if}.
Pretty simple when you look at it, eh?