How to write this on HAML? Help please

155 views
Skip to first unread message

haml_newbie

unread,
Feb 16, 2012, 3:37:22 AM2/16/12
to ha...@googlegroups.com
<script type="text/template" id="comments-template">
      <ol class="comments">
        <% _.each(comments, function(c) { %>
          <li><%= c.title %></li>
        <% }); %>
      </ol>
</script>

It's template for backbone.js

haml_newbie

unread,
Feb 16, 2012, 5:23:46 AM2/16/12
to ha...@googlegroups.com
I tried use filter :javascript, but how set type and id atributes for script tag?
Message has been deleted

haml_newbie

unread,
Feb 16, 2012, 5:40:06 AM2/16/12
to ha...@googlegroups.com
Oh yes! I get it with %script and :plain 

Thanx u all for the help, lol

Lorin Tackett

unread,
Feb 16, 2012, 5:40:25 AM2/16/12
to ha...@googlegroups.com
The :javascript filter is really only useful for writing inline javascript very quickly, but not much else in my experience. Certainly not very helpful for Backbone templates, since the type attribute needs to be something other than text/javascript, and you need to stick an ID onto the emitted script tag.

Instead, what I have done is just emit the tag and use Haml to structure the Backbone templates, business-as-usual.

%script#template-name{ :type => "text/template" }
  %ol.comments
    <% _.each(comments, function(c) { %>
    %li <%= c.title %>
    <% }); %>

Just make sure not to nest the LI tag within your _.each method. As far as Haml is concerned, it should be on the same level of indentation. If it's not, Haml will throw indentation errors.

Just FYI, this is not the way Haml is intended to be used, and it's a bit rough to use it this way. That said, I still prefer Haml over HTML for Backbone templates.

-- 
Lorin Tackett
Browser Wrangler

On Thursday, February 16, 2012 at 2:23 AM, haml_newbie wrote:

I tried use filter :javascript, but how set type and id atributes for script tag?

--
You received this message because you are subscribed to the Google Groups "Haml" group.
To view this discussion on the web visit https://groups.google.com/d/msg/haml/-/EfS9vHJYMqUJ.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.

haml_newbie

unread,
Feb 16, 2012, 6:09:13 AM2/16/12
to ha...@googlegroups.com
Thanx u!
Reply all
Reply to author
Forward
0 new messages