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

echo/print functions #244

Open
oscarotero opened this issue Mar 11, 2017 · 6 comments
Open

echo/print functions #244

oscarotero opened this issue Mar 11, 2017 · 6 comments
Labels
enhancement New feature or request

Comments

@oscarotero
Copy link
Contributor

Hi, thanks for this nice library. 😃
It would be great to have a print/echo function like in php to output code inside a funcion. For example:

<ul>
<? items.forEach(function (item) {
    echo(`<li><a href="${item.url}">${item.title}</a></li>`);
}); ?>
</ul>

I don't know if this is possible and easy to implement, but it would be really useful.

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 11, 2017

@oscarotero I've thought about this myself, but never proposed it.

Adding it would almost certainly be a breaking change though, since it could create variable name collisions with existing templates.

FWIW, you can get something like what you're describing by calling __append('Some text') in your template. __append is an internal function, so there is a possibility this won't always work between versions. Also, calling this manually may throw off line numbers for errors (not sure about this).

@mde would need to make a decision on whether we will ever add official support for a print/echo function.

@oscarotero
Copy link
Contributor Author

A solution to prevent the breaking change could be having an option to configure this. For example:

ejs.render(str, data, { appendFunction: 'echo'; });

By default this could be false (no function) or __append (if it's currently available), but can be renamed to print, echo or whatever.

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 11, 2017

@oscarotero That's a possible solution, in fact I kind of like it. @mde will have the final decision, though.

@mde
Copy link
Owner

mde commented Mar 25, 2017

I think this is a reasonable approach. It doesn't bloat the lib, and is opt-in. We would want to make sure it doesn't break the line count in our error handling. @oscarotero, would you like to put together a PR for this?

@oscarotero
Copy link
Contributor Author

Here's the PR #248 🎉

@RyanZim RyanZim added enhancement New feature or request PR Pending labels Jul 31, 2017
@mde mde removed the PR Pending label Apr 22, 2018
@mde
Copy link
Owner

mde commented Apr 22, 2018

PR merged, thanks!

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

No branches or pull requests

3 participants