Why wouldn't this work?

am I missing something?

<div class="col-70">

        {exp:channel:entries channel="ministries" limit="1" {gv_param_disable_default}}

            <h1 class="section-header">{title}</h1>
            <img class="{switch='drop-shadow body-image-right|drop-shadow body-image-left'}" src="{image}" alt="{image_description}" title="{image_description}" width="350"/>






Come to find out, the switch does work fine though, I didn't realize it's intended use. It doesn't switch every page load or between each entry on separate pages rather, it switches through the iteration (or loop if you will) of entries when you have more than one entry being listed on a page via a single channel entry tag pair.

A good example of how one might use the switch variable and classes would be Zebra Tables where you are switching between a darker and lighter color for each table row.

  • Can you post your surrounding code? The tag looks right but without the context it's hard to troubleshoot. – Derek Hogue Jan 15 '13 at 1:51

surely on a listing of entries you should have dynamic="no" set, like so:

{exp:channel:entries dynamic="no" limit="2" channel="ministries" {gv_param_disable_default}}
  • this is in the main body of the page. If I set it to dynamic="no" with a limit of 2 entries, it displays 2 entries on the same page, which is not the desired effect. If I take the limit parameter out, so it displays all the entries on the same page, the switch variable works, but again, I don't want to display anything other than the current entry on the page. I do have another channel entries tag in the sidebar with dynamic="no" set to display links to all the entries in the channel, but I wouldn't think that would effect anything. – hyphen81 Jan 15 '13 at 11:30
  • 1
    I think you may be missing the purpose of the Switch parameter. The switch parameter will only ever work where there is more than 1 entry. The switch basically alternates syntax between those entries. For example: make the odd entry titles blue and make the even entry titles red. If you only ever want 1 entry to show, then switch won't work. – Steven Grant Jan 15 '13 at 11:51
  • well that's a bummer. I guess I'll go back to the conditional I had in there before. I was trying to find a better way to just vary the content a little bit so not every page looks like a carbon copy. – hyphen81 Jan 15 '13 at 11:57
  • 1
    if you wanted to do that then why not add a custom drop down field to the channel with your classes then when you publish an entry, select the class you want and add that variable into your channel entries tag? – Steven Grant Jan 15 '13 at 12:00

You have a limit=1 set on the entries tag. So there is only 1 iteration in the loop. For the switch tag to work, it needs to have more than one entry to rotate through the values. Setting the limit to 2 or higher will work.

  • I tried it with limit="2", and it didn't work. I removed the limit parameter entirely, and it doesn't work then either. The image appears on the right for every channel entry visited. – hyphen81 Jan 15 '13 at 2:07
  • What is the value of the {gv_param_disable_default}? Try removing the global variable too to see if that works. Might be a conflict – Siebird Jan 15 '13 at 2:21
  • it is disable="categories|member_data|pagination". I tried removing that as well. I'm stumped. – hyphen81 Jan 15 '13 at 2:26
  • 1
    Have you inspected the page output and actually seen that the class is not being applied? I ask because you say "the image appears on the right for every entry" ... Maybe your CSS is wrong? – Derek Hogue Jan 15 '13 at 4:02
  • The output shows "drop-shadow body-image-right" as the class. Double checked my CSS, and there's nothing weird going on there either. – hyphen81 Jan 15 '13 at 11:35

I'm not sure why that's not working to be honest either based on the code you've provided. Someone mentioned the limit and I'm assuming it's safe to say that you do in fact have more than one entry.

Can you try this instead just for kicks and giggles:

class="drop-shadow body-image-{switch='right|left'}"

  • that's a no go. worth a shot though. I do have 7 entries in this channel, for the record. – hyphen81 Jan 15 '13 at 3:01
  • Can you create a blank template somewhere and copy over my version along with the code you have above and see if it works (or is the above code the only thing currently in the template?) Also, try adding the dynamic="no" param to the channel entry tag. – Natetronn Jan 15 '13 at 3:09
  • I'm sure this isn't it but try using double quotes on the switch instead of single quotes. – Anna_MediaGirl Jan 15 '13 at 5:25
  • I've tried double quotes as well:( – hyphen81 Jan 15 '13 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.