2011-10-23 27 views
5

Tôi đang sử dụng ngọc bích cho node.js. Tôi có 1 mixin (thử nghiệm):Jade, mixin && html

mixin some(field, field2) 
    .field!= field 
    .field2!= field2 

tôi cần đưa vào mixin một số mã html, ví dụ:

#test 
    some(a(href='http://test')='test', span.description=description) 

Tôi muốn rằng:

<div id="test"> 
    <div class="field"><a href="http://test">test</a></div> 
    <div class="field2"><span class="description">bla bla bla</span></div> 
</div> 

Làm thế nào tôi có thể làm điều đó? Bây giờ tôi biết chỉ có 1 quyết định xấu xí:

#test 
    - var field = '<a href="http://test">test</a>'; 
    - var field2 = '<span class="description">' + descriptions + '</span>'; 
    mixin some(field, field2) 

Xin lỗi, cho tiếng anh xấu của tôi :)

Trả lời

1

Hình như giải pháp hiện tại của bạn là cách duy nhất. Các tham số cho một mixin là các biểu thức javascript, chứ không phải các phần tử ngọc bích.

1

Trên thực tế bạn có thể vượt qua Jade đánh dấu để mixin cũng

mixin article(title) 
    .article 
    .article-wrapper 
     h1= title 
     if block 
     block 
     else 
     p No content provided 

+article('Hello world') 

+article('Hello world') 
    p This is my 
    p Amazing article 

Tôi biết câu hỏi này là khá cũ. Để lại câu trả lời để người khác có thể thấy nó hữu ích.