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

Include in client side? #69

Closed
dorner opened this issue Feb 17, 2015 · 4 comments
Closed

Include in client side? #69

dorner opened this issue Feb 17, 2015 · 4 comments
Labels
question Further information is requested

Comments

@dorner
Copy link

dorner commented Feb 17, 2015

I might be misunderstanding this, but question about #68 - if I can't render a file on the client side, does that mean that I can't include another template this way - i.e. I can't replicate partials?

E.g. this:

<%= include('my_file', {foo: 'bar'}) %>

is simply not usable client-side? Is there some way to specify a second inline template perhaps?

@titpetric
Copy link

It's possible to write your own function with the same parameters, something like this:

include: function(filename, data) {
        var contents = this.getCache(filename);
        if (contents) {
                return this.getTemplate(contents, data); // basically a call to ejs.render(contents, data);
        }
        return 'Error loading ' + filename;
},

and then using it:

<%- apiBuilder.include('templates/api/call.ejs', { name: name, call: call }) -%>

Keep in mind that it might be a bit work to get it to work asyncronously, and that syncronous requests in the main thread are disabled in some browsers (hello Chrome, do you have any friends?). I pre-populate the template cache, so that getCache() always returns a value when it's called. Or at least it tries to...

With some restructuring, it's possible to "expose" the include* methods and make your own implementation on the client side, but due to the async nature of ajax requests, perhaps some thought should be given how to promisify this.

@puro
Copy link

puro commented Apr 13, 2015

it's possible if you add this function. Be aware that this is a sync request.

 exports.readFileSync = function (path) {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open("GET", path, false);
            xmlhttp.send();
            return xmlhttp.responseText;
        };

after 3: [function (require, module, exports) {

@RyanZim RyanZim added the question Further information is requested label May 5, 2016
@RyanZim
Copy link
Collaborator

RyanZim commented May 5, 2016

Documentation has been updated; see https://github.com/mde/ejs#caveats.

@RyanZim RyanZim closed this as completed May 5, 2016
@frank-dspeed
Copy link

Only for the documentation DoneJS still covers ejs by its original creators (Bitovi) and ejs is still alive on client side its now called can-ejs and got re Integrated into the CanJS Stack

for example the partial client side problem is solved via steal-stache :) if you need a starting point for isomorphic apps and templates simply go to DoneJS.com

https://canjs.com/doc/can-ejs.html but for frontend and backend you should use the new https://canjs.com/doc/can-stache.html

Repository owner locked and limited conversation to collaborators Sep 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants