Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jade, mixin && html

I'm using jade for node.js. I have 1 mixin(test):

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

I need put into mixin some html code, example:

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

I want that:

<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>

How I may do that? Now I know only 1 ugly decision:

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

Sorry, for my bad english :)

like image 629
faiwer Avatar asked Nov 04 '22 12:11

faiwer


2 Answers

Looks like your current solution is the only way. The parameters to a mixins are javascript expressions, not jade elements.

like image 74
Dobes Vandermeer Avatar answered Nov 09 '22 12:11

Dobes Vandermeer


Actually you can pass Jade markup to mixin as well

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

I know this question is quite old. Leaving reply so that someone else might find it helpful.

like image 30
Andreyco Avatar answered Nov 09 '22 11:11

Andreyco