How do I alternate styles for entries or sidebar?

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

How do I alternate styles for entries or sidebar?

Post 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
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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">
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

Hey that was quick,

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

Carl
Guest

Is this

Post by Guest »

carl_galloway wrote:Hey that was quick,
Is this what I think it is? ... Thats awesome!:)
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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?
Post Reply