Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add multi-line script in partial view? #19

Open
naprirfan opened this issue Jun 7, 2016 · 3 comments
Open

How to add multi-line script in partial view? #19

naprirfan opened this issue Jun 7, 2016 · 3 comments

Comments

@naprirfan
Copy link

naprirfan commented Jun 7, 2016

Hi,

Please help. I have this master.ejs layout :

<!DOCTYPE html>
<html>
<head>
<title>The title</title>
</head>

<body>
  <%- body %>

  <!--Lots of script-->
  <script src="/a.js"></script>
  <script src="/b.js"></script>
  <script src="/c.js"></script>
  <script src="/d.js"></script>

  <!--Additional script-->
  <%- block('script') %>
</body>
</html>

How do I add another multi-line long script inside block('script')? Consider I have this partial view :

<% layout('master') %>

<!-- For body -->
<div>BODY</div>

<!--For script -->
<% block('script').append("<script>") %>
<% block('script').append("console.log('hello world!');") %>
<% block('script').append("console.log('another line!');") %>
<% block('script').append("<script>") %>

It's less readable and very tedious. Also, I'm gonna need to inject variables to this JS. Any suggestion?

Thanks before!

@naprirfan
Copy link
Author

Nevermind. I solve it by creating script file, and call it from the partial view.

<%- block('script').append(partial('script.ejs', { data: data })) %>

@JacksonTian
Copy link
Owner

why not write <script>your code</script> directly?

@naprirfan
Copy link
Author

Because the order of the scipts matter, and I can't write script directly because it will show before <script src="/a.js"></script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants