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

It would be more useful to import the compiled template than the generated text #1

Closed
bary12 opened this issue Jun 28, 2018 · 5 comments

Comments

@bary12
Copy link

bary12 commented Jun 28, 2018

ejs templates are meant to be used with different render data, and when importing them, there is no way to pass render data.
I think it will be more useful to import the compiled template instead.

How it works currently

<button><% buttonText %></button>
import rendered from './template.ejs';

results in error: buttonText is not defined

The Suggestion

With the same ejs file,

import template from './template.ejs';
const rendered = template({
    buttonText: 'Click Me'
});

This change would be a matter of changing this line from return compiled(); to return compiled;.

@wulisensen
Copy link

I very much agree with your suggestion.

I'm trying to use parcel from webpack.Now, i get a trouble about parcel-plugin-ejs: names is not defined.

<% if (names && names.length) { %> <% names.forEach(function(src,index){ %><video class="advideo" data-tag="<%= index %>"style="position:absolute;top:0;left:0;display:none;" poster="http://p1.ifengimg.com/a/2016/1021/loading0.jpg" src="<%= src %>" id="adPlayer" preload="auto"></video><% }) %> <% } %>

How to solve this problem now...

@bary12
Copy link
Author

bary12 commented Jul 7, 2018

@thoughtbyte any thoughts about this? Take in mind that this is how webpack's ejs-loader works, and it seems to be a much better use for this plugin.

@vabruzzo
Copy link
Owner

yep, thanks for the suggestion. i will be updating this.

the reason i published this first is to sue as a base for a custom ejs plugin that will read variables directly from the template file, in the form of front-matter, but i will make this change here!

thanks!

@vabruzzo
Copy link
Owner

fixed in 0.2.0

@LucienLee
Copy link

How about work as pug in parcel?
put the data into ejs.config.js and compile with it
https://github.com/parcel-bundler/parcel/blob/75310e15f6fa3c8a0ce6593ada1bcca00240ea54/packages/core/parcel-bundler/src/assets/PugAsset.js#L36

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

4 participants