For some reason I can’t figure out, the “Search this blog” function in Blogger is implemented using ActiveX (at least when you use IE to view a blog). If like me, you care about security and have disabled ActiveX this poses an obvious problem. I whipped up a 2 line form that lets you search without having ActiveX enabled and made it conditionally show only in IE.
The problem is, it didn’t show up at all!
I have conditional comments to load up IE-specific CSS fixes… so why didn’t the same tags work in the body? I looked again and noticed that the content didn’t even show up in the page source… it looked like Blogger was removing the comment (instead of letting the browser do it). I had already encountered a problem with Blogger and conditional tags so it didn’t surprise me that something odd was happening.
So there’s 3 thing you need to know about conditional tags in Blogger templates.
The first is that downlevel-revealed tags (<![if !IE]>HTML<![endif]>) don’t work at all. Blogger chokes on these because I guess they aren’t valid XML.
The second is that comments, including downlevel-hidden tags (<!–[if IE]>HTML<![endif]–>), are removed by Blogger if they are inside widgets. Since HTML is only allowed outside of sections and inside widgets that means you need to arrange the conditional content to live in one of these areas.
For me it was easy. I’ve got a positioning div for the sidebar on the right. I have a section that holds the widgets that make up the content of the sidebar. I had originally put the search box inside the first widget but that means Blogger removes the content. Moving the content above the section (but still in the positioning div) makes it appear at the top of the sidebar.
Now if I’d wanted it in the middle of your sidebar… that can be done but you have to close the section and create another one after the conditional stuff. For me that’s a problem because sections have to have unique IDs and my CSS styles the sidebar based on id rather than class. Mind you, that’s just a tweak to the CSS to fix. I tested it out and it works. It makes the GUI layout tool a bit strange to look at but then I only use that to edit widget settings, my template is all hand-crafted.
The third thing you need to know is that blogger magic doesn’t work inside conditional comments. Outside of sections they’re not stripped from the output but the Blogger engine doesn’t look inside them. I’m constructing the search form’s action field using the expr: notation but since that doesn’t work with conditional comments I’ve had to change it to just be inside a div that’s display:none for all except IE. I suppose I could have hard-coded the blog URL in there but I don’t like doing things like that.