ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Using {switch} to customize Discussion Forum Templates?

November 09, 2010 12:39am

Subscribe [5]
  • #1 / Nov 09, 2010 12:39am

    C. Reeves

    20 posts

    I’m using Discussion Forum v2.1.1.

    I’m trying to customize my forum template code to have alternating bg colors for individual posts within a thread so that the first post’s bg color is light, the following reply post has a dark bg, then the next a light, and so on.

    I’ve seen some stuff around the forum and tried a few things but I can’t get it to work and I don’t understand it. I’ve seen how it’s used outside of the forum, where it goes in a {exp:search:search_results switch="odd|even"} tag, but there’s no tag like that in the discussion forum templates.  Further more, are these “odd” and “even” classes hard-coded into the EE system or can we use any name we choose… like “light” and “dark”?

    I’m just really lost on how to achieve this effect on the forum templates, can anyone help?

    -Chris

  • #2 / Nov 09, 2010 3:26pm

    Ingmar

    29245 posts

    Really Fourm module 2.1.1? What build? Also, what version and build of EE are you using?

    I’ve seen how it’s used outside of the forum, where it goes in a {exp:search:search_results switch=“odd|even”} tag, but there’s no tag like that in the discussion forum templates.

    That’s correct. You’d have to use PHP for that.

    Further more, are these “odd” and “even” classes hard-coded into the EE system or can we use any name we choose… like “light” and “dark”?

    Yes, you can name them anything.

  • #3 / Nov 09, 2010 3:44pm

    C. Reeves

    20 posts

    Yes, forum v.2.1.1 and I’m not sure what build it is. I’m not sure where to find that information for that module.  EE system is v1.6.8 build: 20091002.  I realize both of these are dated versions. Unfortunately, I can’t afford to re-subscribe and download the new versions right due to personal reasons. So I have to work with what I have for now.

    I found this in the Discussion Forum Guide…

    Version 1.3.2
    Release Date: November 28, 2006
    Added a “switch” variable to the Thread Rows, Thread Review Rows, Topic Rows, and Search Results Rows templates. Syntax: {switch="one|two|..."}

    It seems like this is implemented in the forum system already and will achieve what I want to do. Can you explain how to use this? The documentation on it isn’t very clear to me at all.

  • #4 / Nov 10, 2010 2:30am

    John Henry Donovan

    12339 posts

    C. Reeves,

    The switch variable does indeed work within your forum templates. If you open up the Thread Rows template you can add switch to any piece of mark-up you wish

    So if you had two styles called .light and .dark you would add a switch variable like this

    <tr class="{switch='light|dark'}">

    Does that make more sense?

  • #5 / Nov 10, 2010 11:56am

    C. Reeves

    20 posts

    Thanks for the reply! It does make sense now. However, I still can’t get it to work. I’m going to post the bottom half of the code from my Thread Rows template. The overall structure of the tables is still default. My code starts with the row that the avatar cell and post cells are in followed by the button row.  I believe my code would alternate the switch classes between the avatar + post row and the button row in theory… but it’s not working.

    
    
    

    Ideally, I want the button row to have the same background color as the avatar + post row. So if we go by this code you have 4 rows for 2 posts and the coloring should be like this - light, light, dark, dark. Right now EVERYTHING has NO background… you just see through to the forum’s bg. My “lightRow” class is slightly darker than the forum bg, and “darkRow” is darker still.

    What am I missing?

  • #6 / Nov 11, 2010 7:12am

    John Henry Donovan

    12339 posts

    C. Reeves,

    It looks like you switch tag is working though right?

    I am going to move this thread to the CodeShare Corner now as it is more appropriate there now

    If you had a link to the forum it may help other users who wish to chime in here.

  • #7 / Nov 11, 2010 11:40am

    C. Reeves

    20 posts

    Erm… no, it’s not working. That’s why I came here. :( I used the code exactly like you said to and still no dice.

    Here’s an test thread people can look at. Forum Link

    What you see there is using the code I previously posted. The darker row you see on the post comes BEFORE the switch row and should not be effected anyway. It’s the one with all the admin info in it and uses an image for its bg. So if you say that code looks correct, then what else could this be? I doubt it’s the CSS, but I’ll post that anyway…

    .lightRow {
     background: #EBEBEB;
    }
    
    .darkRow {
     background: #E1E1E1;
    }

    What’s wrong with this thing and why won’t the switch work?

  • #8 / Nov 12, 2010 1:09am

    John Henry Donovan

    12339 posts

    C. Reeves,

    Sorry my mistake. I believed the switch to be working just not your implementation of the CSS.

    Your link was helpful as when I viewed your source I could see the switch variable was actually working. You just have a curly quotes in there instead of a double apostrophe. See attached

    Try copying and pasting exactly this

    <tr class="{switch='lightRow|darkRow'}">
  • #9 / Nov 12, 2010 1:18am

    C. Reeves

    20 posts

    Thanks! That did the trick… problem solved.

  • #10 / Nov 12, 2010 1:19am

    John Henry Donovan

    12339 posts

    Glad to have helped. Sorry for the confusion halfway through the thread.

  • #11 / Nov 18, 2010 10:36am

    humanequation

    6 posts

    Is the switch variable available for the Index Page Templates/Forum Table Rows template? It doesn’t seems to work (same version and build).

  • #12 / Nov 30, 2010 1:31pm

    LCBC Church

    29 posts

    I am experiencing the same problems. The switch tag isn’t working in my code. I am wondering if I can’t use it in conjunction with the categories tag. Here is my code:

    {exp:channel:categories channel="events" category="2" show_empty="yes" dynamic="no" style="linear"}
    <li><a href="#class={switch=xsmall|large}">{category_name}</a></li>
    {/exp:channel:categories}

    Any thoughts on why this isn’t working, please help!

  • #13 / Apr 18, 2011 3:05pm

    I’ve been unable to use the Switch tag with exp:channel:categories too.
    Anyone managed to solve this?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases