-
Notifications
You must be signed in to change notification settings - Fork 847
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
added custom output function name #248
Conversation
examples/functions.ejs
Outdated
@@ -1,7 +1,7 @@ | |||
<h1>Users</h1> | |||
|
|||
<% function user(user) { %> | |||
<li><strong><%= user.name %></strong> is a <%= user.age %> year old <%= user.species %>.</li> | |||
<li><strong><%= user.name %></strong> is a <%= user.age %> year old <% echo (user.species) %>.</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since echo
is a function, there shouldn't be a space between the function name and the parens. Should look like echo(user.species);
.
Also, rather than having this example mixed together with the output tag, might it not make sense to have a totally separate example?
examples/functions.js
Outdated
var ret = ejs.compile(read(path, 'utf8'), {filename: path})(data); | ||
var ret = ejs.compile(read(path, 'utf8'), { | ||
filename: path, | ||
outputFunctionName: 'echo' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same feedback as above -- since this is not likely the default use-case, it make make more sense to make this a separate example.
I've added a couple of comments. Sorry for the delay in responding. |
Thank for the feedback. I've commited the changes. |
examples/output-function.ejs
Outdated
@@ -0,0 +1,3 @@ | |||
<p> | |||
<strong><%= echo(name) %></strong> is a <%= echo(age) %> year old <% echo(species) %>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you neglected to change all tags to script-execution tags. In fact, you might want to make your example look more like your real use-case. For example, you might want to use output during debugging or something? You could even include a couple of examples of different ways to use it. It's good for people to know why this feature exists.
One more comment .... :) |
Also, did you verify if it plays nicely with the line-numbers in errors? |
Ok, now it has a more realistic example.
as you can see, the error is in line 4, not 2, not sure whether it's a problem with |
Try your same error without the |
Same error:
|
Ah, might be the line number for the opening tag. It's been a long time since I touched that code. I'll play around with it and see what it's doing to make sure this doesn't confuse things. |
Hi. Any plans for a new release including this feature? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM, needs docs yet.
@mde @User4martin Thoughts on this?
Any changes on this? Really want this feature, as I several days ago switched to Node from PHP and having similar syntax would be amazing for me. |
Is this not sufficient? <% for (const user of users) { %>
<li><%= user.name %></li>
<% } %> |
Sorry for the lengthy delay on this. I've verified there's no change to line numbers in errors. Thanks very much for this! |
Great! |
@ViktorQvarfordt is more readable. |
According with #244 I've added a new option to define an output function name like
echo
orprint
. Example:Any suggestion is welcome