2015-02-09 32 views
0

我在前端使用haml和mustache。有一個代碼片段:在haml中使用變量設置屬性

.module-subtitle 
    {{title}} 

我想顯示.module的字幕與標題屬性的提示,使用裏面的內容的{{title}}。我試過

.module-subtitle{ :"title" => {{title}}} 
    {{title}} 

但它沒有工作,因爲它有語法錯誤。任何提示?

回答

0

你可以使用:plain,像這樣:

:plain 
    <div class="module-subtitle" title="{{title}}"> 
    {{title}} 
    </div> 
1

沒有看到更多的代碼和運行一些實驗,我最初猜測它是模板渲染的順序。如果Haml先渲染,那麼它不會喜歡.module-subtitle{ :"title" => {{title}}}。如果Mustache首先運行,則應將.module-subtitle{ :"title" => {{title}}}替換爲.module-subtitle{ :"title" => YourTitle},但還要注意,在這種情況下,YourTitle不是字符串分隔的。

如果你的對象在haml渲染上下文中可用,那麼你可以把它留給哈姆渲染? .module-subtitle{ title: my_object.title}

相關問題