Search code examples
ruby-on-rails-3backbone.jsclient-side-templatinghamlc

How to embed raw html string attribute into .hamlc template?


Currently I have backbone RIA with rails backend. I'm using haml_coffee_assets gem for client-side templating. But I miss rails view helpers there.

I decided to add raw html strings into my backbone models. So, I have this kind of object in my coffeescript

Object
  avatar: "/avatars/small/missing.png"
  avatar_link: "<a href="/users/ortepko" class="author" id="user-nick-76"><img src="/avatars/small/missing.png" width="32" /></a>"
  humanized_messages_number: "1 Message "
  id: 76
  login_name_link: "<a href="/users/ortepko" class="author" id="user-nick-76">ortepko</a>"

my template code becomes pretty simple

.text_content
  .comment
    = @contact.avatar_link
    .text
      = @contact.login_name_link
      .messages
        %a{href: '#'}
          = @contact.humanized_messages_number

Now I want to render a template

JST['messages/yet_another_template'] {contact: contact}

But it does not seem to be working.


Solution

  • I have found an answer here: Partials in Coffee HAML (.hamlc)

    My Template should look like

    .text_content
      .comment
        != @contact.avatar_link
        .text
          != @contact.login_name_link
          .messages
            %a{href: '#'}
              = @contact.humanized_messages_number
    

    Thanks to Netzpirat!