Page 1 of 1

How do I alternate styles for entries or sidebar?

Posted: Sun Dec 18, 2005 5:19 pm
by carl_galloway
Hi all,

I'm wondering if I can use the following smarty code to alternate the styles for either entries on the startpage, or for sidebar titles on every page. I've had an idea for a completely new theme, but to make it really stand out I need to alternate styles, especially the sidebar.

Code: Select all

{if $smarty.foreach.comments.iteration is odd}graybox{/if}
I have tried replacing 'comments' with other variables that I've found in the entries.tpl or sidebar.tpl but none seem to work, I wonder if this is because they aren't odd or even. Can this be done? Would I be able to incorporate this into a theme without having to install a new plugin?

Thanks for any help,
Carl

Posted: Sun Dec 18, 2005 7:59 pm
by judebert
I think you'll be better off using the {cycle} tag. I'm (still) no Smarty expert, but here's my modification for the sidebar.tpl in templates/default/:

Code: Select all

<div class="serendipitySideBarItem container_{$item.class} {cycle values="graybox, redbox"}">
The {cycle} tag will insert the next value each time it's called, then go back to the first. This allows it to work with alternations by threes, for instance.

Similarly, for comments.tpl (again from templates/default/), you could change the <div> after the first {foreach} thusly:

Code: Select all

<div class="serendipity_comment serendipity_comment_author_{$comment.author|@makeFilename} {if $entry.author == $comment.author}serendipity_comment_author_self{/if} {cycle values="graybox, redbox"}" style="padding-left: {$comment.depth*20}px">

Posted: Mon Dec 19, 2005 1:04 am
by carl_galloway
Hey that was quick,

I'll try it out over the next couple days. Thanks,

Carl

Is this

Posted: Wed Dec 21, 2005 7:33 pm
by Guest
carl_galloway wrote:Hey that was quick,
Is this what I think it is? ... Thats awesome!:)

Posted: Wed Dec 21, 2005 10:31 pm
by judebert
Y'know, Carl's been working with themes a lot lately. If he needs Smarty help, I'm gonna provide it as quickly as I can.

So, Carl, what's under the hat?