hsz
hsz

Reputation: 152266

Jade helper for FontAwesome

I want to write some helper for FontAwesome in jade template in Express.js, so I did in app.js:

app.locals.icon = function(icon){ return '<i class="fa fa-' + icon + '"></i>'; };

and called in template:

block content
  h1= title
  p Welcome to #{title}
  = icon('users')

however it returns me escaped HTML code. What is a good practise for writing this kind of helpers ? How to return raw HTML ?

Upvotes: 2

Views: 1494

Answers (1)

damphat
damphat

Reputation: 18956

Try with != operator

 != icon('users')

Refrence from http://jade-lang.com/

Unescaped buffered code starts with != and outputs the result of evaluating the JavaScript expression in the template. This does not do any escaping, so is not safe for user input.

Upvotes: 2

Related Questions