Giter Site home page Giter Site logo

Include in client side? about ejs HOT 4 CLOSED

mde avatar mde commented on August 23, 2024
Include in client side?

from ejs.

Comments (4)

titpetric avatar titpetric commented on August 23, 2024

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.

from ejs.

puro avatar puro commented on August 23, 2024

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) {

from ejs.

RyanZim avatar RyanZim commented on August 23, 2024

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

from ejs.

frank-dspeed avatar frank-dspeed commented on August 23, 2024

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

from ejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.