RandomEtc / ejs-locals

Express 3.x layout, partial and block template functions for the EJS template engine.
298 stars 63 forks source link

<%- stylesheet('abc.css') %> in a layout file #16

Closed ghost closed 11 years ago

ghost commented 11 years ago

I want to define some common css files in the layout with stylesheet for short. But the following code

<%- stylesheet('abc.css') %>
<%- stylesheets %>

generates:

<link rel="stylesheet" href="abc.css">
<link rel="stylesheet" href="abc.css">         // duplicate

Is that mean I should write

<link rel="stylesheet" href="abc.css">

in the layout instead of using stylesheet? Thanks.

RandomEtc commented 11 years ago

You're almost there. For the call to stylesheet you don't want to include the output, so you'll do <% stylesheet('abc.css') %> (without the - before stylesheet).

Let me know if that doesn't work?

ghost commented 11 years ago

@RandomEtc It works. Thanks. I am new to ejs and I should read more about it. :)

RandomEtc commented 11 years ago

Great - closing this issue.

The main thing to know is that you almost always want <%=variable %> which will safely HTML-escape your data. If you do <%-variable%> this is only safe if the data is already escaped. And without the = or - then you're just calling a function or running javascript: there's no output into your markup.

Hope that helps!