<%- stylesheet('abc.css') %> in a layout file
Closed this issue · 3 comments
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.
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?
@RandomEtc It works. Thanks. I am new to ejs and I should read more about it. :)
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!