2011-08-12 31 views
1

我想要遵循這個Rails/Backbone的例子,但他們使用erb而不是haml。見線45-48如何添加一個ID屬性腳本與HAML的:javascript filter

https://github.com/AndrewGertig/backbone-demo/blob/master/app/views/dogs/index.html.erb

這似乎並沒有被id屬性腳本,所以它看起來像...

<script id="dog_template" type="text/html"> 
    <td>{{name}}</td> 
    <td>{{age}}</td> 
</script> 

回答

5
%script{:id => "dog-template", :type => "text/html"} 
    %td {{name}} 
    %td {{age}} 

你可以嘗試一下here

+0

明顯,現在我想想:可能的補充。謝謝。 我想這可能是一個問題,如果我把任何其他的JavaScript模板在那裏。 我發現的另一種方法是使用:erb過濾器代替。 –

+0

我更喜歡%script#dog-template將id放入{} – makevoid

+0

任何方法在腳本標記內寫入JSON代碼?有關我的意思的詳細信息,請參閱我的帖子http://stackoverflow.com/questions/33636072/haml-json-add-a-script-tag-of-type-application-json。 – Cody

相關問題