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 class not working?

November 27, 2012 8:06am

Subscribe [4]
  • #1 / Nov 27, 2012 8:06am

    ciprian

    17 posts

    I’m having a problem with a simple class=”{switch='even|odd'}”

    I have some categories I need to display alternatively with different backgrounds, here is my code:

    {exp:channel:categories channel="legal_services" style="linear"}
      {exp:channel:entries channel="sections" category="{category_id}"}
                        <div class="{switch='even|odd'}">
                            <h4>{category_name}</h4>
    <p>                        {section_intro}<br />
                            <a href="http://{path=what/section_legal}">More ></a><br />
                         <div class="img-wrapper"><br />
        {section_images}<br />
                             {section_img_small}<br />
        {/section_images}<br />
                         </div><br />
                        </div><br />
      {/exp:channel:entries}<br />
      {/exp:channel:categories}

    and here is the page:

    http://www.efc.ie/test/what/legal

    I have only 3 entries at the moment, for testing.

    The page should be rendered like this:

    http://zinc.ie/collins/what-legal.html

    So the boxes have two different backgrounds respectively.

    What am I doing wrong?

     

  • #2 / Nov 27, 2012 9:27am

    tigercore

    24 posts

    This is odd, the syntax looks correct.

    In fact I’ve just copied your code into one of my projects and just changed the channel names to match one’s I have and it’s working fine.

    You’re link at http://www.efc.ie/test/what/legal is broken though, so I can’t see your rendered page. Can you fix and I’ll take another look.

  • #3 / Nov 27, 2012 9:32am

    ciprian

    17 posts

    This is odd, the syntax looks correct.

    In fact I’ve just copied your code into one of my projects and just changed the channel names to match one’s I have and it’s working fine.

    You’re link at http://www.efc.ie/test/what/legal is broken though, so I can’t see your rendered page. Can you fix and I’ll take another look.

    Thank you very much for your answer!

    Yes very strange, I’ve checked the code a million times, I don’t know what I’m doing wrong!!! The divs are all with a class of “even”, the switch doesn’t trigger the “odd” class.

    The link http://www.efc.ie/test/what/legal works fine on all my browsers, I’ve checked it and I’m posting again, hope it works!

  • #4 / Nov 27, 2012 5:57pm

    Wouter Vervloet

    758 posts

    Hi landozinc,

    How many categories do you have on that page, because I suspect the {switch} tag is being parsed by the channel:categories tag instead of the channel:entries tag. So if you’re showing just 1 category the switch tag is only showing the first value…

    – Wouter

  • #5 / Nov 28, 2012 4:54am

    ciprian

    17 posts

    Hi landozinc,

    How many categories do you have on that page, because I suspect the {switch} tag is being parsed by the channel:categories tag instead of the channel:entries tag. So if you’re showing just 1 category the switch tag is only showing the first value…

    – Wouter

    That’s a good observation, I do have several categories on my page: Banking, Corporate M&A, etc, and they’re all showing on that page.

    How do I get the {switch} tag to be parsed by the channel:entries tag instead of the channel:categories?

  • #6 / Nov 28, 2012 11:21am

    ciprian

    17 posts

    Just bumping this…

    any suggestions?

  • #7 / Dec 01, 2012 1:27pm

    Kurt Deutscher

    827 posts

    Hi landozinc,

    I’m guessing you’ll want to embed the Channel tag, basically split the work into two templates.

    Keep the one you have, and reduce it down to something like this:

    {exp:channel:categories channel="legal_services" style="linear"}
    
         {embed="category_group/channel_helper_sections" category_id="{category_id}"}
    
    {/exp:channel:categories}

    Then set up a new one called “channel_helper_sections” (or whatever you want to call it) with your channel tag in it.

    {exp:channel:entries channel="sections" category="{category_id}"}
                        <div class="{switch='even|odd'}">
                            <h4>{category_name}</h4>
    <p>                        {section_intro}<br />
                            <a href="http://{path=what/section_legal}">More ></a><br />
                         <div class="img-wrapper"><br />
        {section_images}<br />
                             {section_img_small}<br />
        {/section_images}<br />
                         </div><br />
                        </div><br />
      {/exp:channel:entries}

    This way the channel tag will parse first, and only its results will get embedded into the Categories tag.

    Note that this method uses a lot of queries, so I would add everything you can to the “disable” paramater in both your Categories and Channel tags to cut down on the work required here. You can look up the “disable” parameters in the docs if they are new to you.

    Don’t forget to pass the category_id in your embed tag, AND you want to add a dynamic=“no” parameter to the channel tag too I think.

  • #8 / Dec 03, 2012 10:52am

    ciprian

    17 posts

    Thank you for your reply, Kurt Deutscher.

    Unfortunately, your code is not working. I will try and work with it a bit and see if it works.

  • #9 / Dec 03, 2012 11:27am

    Kurt Deutscher

    827 posts

    Here’s a working example from one of our sites that uses this method to create an FAQ page with questions and answers sorted by category:

    http://reachcdc.org/properties/faqs/

    In the example page, each question and answer is a separate entry.

    Template: site_display/faq

    {exp:channel:category_archive channel="{embed:host_language_channel_name}" style="linear" show="not 69"}
      {categories}
       <h1>{category_name}</h1>
       <dl>
        {embed='site_display/custom_faq_engine' host_language_channel_name='{embed:host_language_channel_name}' category_id='{category_id}'}
       </dl>
      {/categories}
     {/exp:channel:category_archive}

    Template: site_display/custom_faq_engine

    {exp:channel:entries channel='{embed:host_language_channel_name}' dynamic='{embed:dynamic}' limit='30' category='{embed:category_id}' disable='pagination|member_data'}
    
    <dt>{count}.  {title}</dt>
    <dd>{main_content_english_usa}</dd>
    
    {/exp:channel:entries}

    This embeds the channel tag inside of a categories tag (well in this case it’s a category_archive tag, but the concept is the same.

    If this still doesn’t fix up that switch issue, then it might be a bug, but embedding it is my best guess as to how to get it working.

    Say, if anyone finds this example and wants to use it, you’ll want something along these lines to get the answers to collaps:

    [removed]
    $(document).ready(function(){
     $("dd").hide();
     $("dt").click(function(){$(this).next().toggle();});
    });
    [removed]

    This example is from an older site of ours, but should still work fine for folks.

    Hope you get your switch working!

  • #10 / Dec 05, 2012 11:29am

    ciprian

    17 posts

    Hi Kurt Deutscher,

    I have tried your code, embed variables, also other different options, but unfortunately the switch tag still doesn’t work.

    Thank you very much for your help anyways!

  • #11 / Dec 05, 2012 11:29am

    ciprian

    17 posts

    Hi Kurt Deutscher,

    I have tried your code, embed variables, also other different options, but unfortunately the switch tag still doesn’t work.

    Thank you very much for your help anyways!

  • #12 / Dec 05, 2012 11:53am

    ciprian

    17 posts

    I actually fixed the problem with jQuery switch class so it’s all working fine now.

    Don’t bother with EE when you can fix things with a simple line of [removed]-)

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

ExpressionEngine News!

#eecms, #events, #releases