views:

33

answers:

1

I'm trying to accomplish the following content in source code:

<div id="box<%=id%>"></div>

Without escaping any signs in Haml.

%div{ :id => "box_<%=id%>" }

produces

<div id='box_&lt;%=id%&gt;'></div>

Right now the only way I can do this with Haml is to use :plain filter and hardcode HTML without using any View Helpers. How can I fix that?

I need this because I'm forced to follow this convention because of third-party syntax convention: JavaScript Micro-Templating

Reference:

Haml reference

+1  A: 

You say you're coding in Haml, but the brackets indicate Erb.

  • Step 1. Try normal Ruby interpolation:

    %div{ :id => "box_#{id}" }
    
  • Step 2. There is no step 2.

David Jacobs
Sorry but I don't code. I code in Haml and need <%=id%> unescaped in source code(Micro-Templating link explains the syntax). David, how can I fix that?
Fedyashev Nikita
I'm confused. You're generating a template for one language to parse using *another* templating language? I don't think I would go this route.
David Jacobs
Right :) Probably Micro-Templating link will explain it better.
Fedyashev Nikita
I read that link. It doesn't make sense to me, why you would want to stack *two* templating languages on top of each other. Each templating language is going to do funny things like escape characters you don't want it to escape, etc. And each one will have its own parser. I would interpolate variables once and not mess with nested parsers.
David Jacobs
Unfortunately I have to disagree with you. John Resig's Micro-Templating works well for me just like for many other people. And I can not refuse it. The question was not about whether it is a good or not.
Fedyashev Nikita
Sorry if that comment wasn't clear. What I mean to say is: **What you want can't be done easily** (if at all) because using two templating languages on top of each other is not a common use case.I would suggest coding your templates in raw HTML.
David Jacobs
OK, thanks for your time and advice David
Fedyashev Nikita