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.

Switch not working inside a calendar tag

July 27, 2009 2:21pm

Subscribe [2]
  • #1 / Jul 27, 2009 2:21pm

    srosenow

    15 posts

    I am trying to set up a calendar where the class of each date cell alternates using the switch parameter. Instead of alternating classes, however, it is assigning a class of “{switch='one|two'}” to every cell. My code is included below. Can anyone help?

    {exp:weblog:calendar switch="calendarToday|calendarCell" weblog="events"}
    
                <table class="calendarBG" border="0" cellpadding="0" cellspacing="0" summary="My Calendar" width="100%">
                <tr class="calendarHeader">
                <th><div class="calendarMonthLinks"><a href="http://{previous_path=weblog/cal}"><<</a></div></th>
                <th colspan="5">{date format="%F %Y"}</th>
                <th><div class="calendarMonthLinks"><a href="http://{next_path=weblog/cal}class=calendarMonthLinks">>></a></div></th>
                </tr>
                <tr>
                {calendar_heading}
                <td class="calendarDayHeading">{lang:weekday_short}</td>
                {/calendar_heading}
                </tr>
    
                {calendar_rows }
                {row_start}<tr>{/row_start}
    
                {if entries}
                <td class="{switch='one|two'}" align='center'>
                <div class="date-cell">{day_number}</div>
                {entries}
                <div><a href="http://{title_permalink=weblog/index}">{title}</a></div>
                {/entries}
                </td>
                {/if}
    
                {if not_entries}
                <td class="{switch='one|two'}" align='center'><div class="date-cell">{day_number}</div></td>
                {/if}
    
                {if blank}
                <td class="{switch='calendarBlank one|calendarBlank two'}"><div class="date-cell">{day_number}</div></td>
                {/if}
    
                {row_end}</tr>{/row_end}
                {/calendar_rows}
                </table>
                {/exp:weblog:calendar}
  • #2 / Jul 27, 2009 4:55pm

    Ingmar

    29245 posts

    {switch} works a little differently than the one available in the weblog entries tag. This parameter lets you define two states: the “today” state and “all other” states. Typically, this is used to define two CSS classes which are applied to the table cell holding the day of the month.

    You cannot use it to arbitrarily assign alternating classes.

  • #3 / Jul 28, 2009 3:23pm

    srosenow

    15 posts

    Thanks for the help. I knew that switch worked differently in the calendar tag from the documentation, but I was under the impression that it would still function on elements within the calendar tag. Regardless, I managed to accomplish what I wanted with some simple JavaScript. I am now experiencing another problem, though. Maybe I don’t really understand how this tag functions, but the previous and next month links seem to behave strangely for me. I am using the LG .htaccess generator to remove “index.php” from my urls, but when I click on the previous or next month links, it generates a url with “index.php” in it. I am also embedding elements in my sidebar div (right near the top of my code), and although they show up on the main calendar page, they disappear once I navigate to a different month.

    Any ideas what might be causing these things? My code is below.

    {embed="includes/header" page_title="Calendar"}
    
        <div id="sidebar">
            {embed="includes/side_bucket" id_number="2"}
            {embed="includes/side_bucket" id_number="3"}
        </div>
        
        <div id="content">
            <div id="crumbs">
                Home  :  Events  :  Calendar
            </div>
    
            [removed]
                $(document).ready(function(){
                    $('table.calendarBG tr td:first-child').addClass('alt');
                });
            [removed]
    
            <div id="calendar">
    
                {exp:weblog:calendar switch="calendarToday|calendarCell" weblog="events" show_future_entries="yes"}
    
                <table class="calendarBG" border="0" cellpadding="0" cellspacing="0" summary="My Calendar" width="100%">
                    <thead>
                        <tr class="calendarHeader">
                        <th colspan="7">{date format="%F %Y"}</th>
                        </tr>
                        <tr>
                        {calendar_heading}
                        <td class="calendarDayHeading">{lang:weekday_short}</td>
                        {/calendar_heading}
                        </tr>
                    </thead>
                    
                    <tbody>
                        {calendar_rows }
                        {row_start}<tr>{/row_start}
    
                        {if entries}
                        <td class="{switch}" align='center'>
                        <div class="date-cell">{day_number}</div>
                        {entries}
                        <div><a href="http://{title_permalink=events/details}title={embed=id={entry_id}">{title}</a></div>
                        {/entries}
                        </td>
                        {/if}
    
                        {if not_entries}
                        <td class="{switch}" align='center'><div class="date-cell">{day_number}</div></td>
                        {/if}
    
                        {if blank}
                        <td class="{switch} calendarBlank"><div class="date-cell">{day_number}</div></td>
                        {/if}
    
                        {row_end}</tr>{/row_end}
                        {/calendar_rows}
                    </tbody>
                    
                    <tfoot>
                        <tr>
                            <td colspan="7">
                                    <a href="http://{previous_path=events/calendar}class=left">« Previous Month</a><a href="http://{next_path=events/calendar}class=right">Next Month »</a>
                            </td>
                        </tr>
                    </tfoot>
                </table>
                {/exp:weblog:calendar}
    
            </div>
        </div>
    
    </div>
    
    {embed="includes/footer"}
  • #4 / Jul 28, 2009 5:49pm

    Ingmar

    29245 posts

    I managed to accomplish what I wanted with some simple JavaScript.

    I am very glad to hear this. As to your second issue, may I ask you to start a new thread? We’d like to keep every issue to a thread of its own, makes things much easier for everybody. Thanks.

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

ExpressionEngine News!

#eecms, #events, #releases