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

Additional examples #11

Open
tet123 opened this issue Dec 11, 2015 · 0 comments
Open

Additional examples #11

tet123 opened this issue Dec 11, 2015 · 0 comments

Comments

@tet123
Copy link

tet123 commented Dec 11, 2015

Thank you for a great project! I really want to continue to use it, but I can't get my head around how to expose the different templates so I can execute them programmatically. I followed your examples, but I can only get them to self-execute. I know this is probably not the correct forum to ask this, but I thought more people might be interested so I thought what the heck.

My thought was to do like this.

In the build.js file

var compiledTemplates = {};


compiledTemplates.myTemplate1 = function (data, selector) {
    var tpl = require('./myTemplate1.vash');

    document.querySelector(selector).innerHTML = tpl(data);
}

compiledTemplates.myTemplate2 = function (data, selector) {
    var tpl = require('./myTemplate2.vash');

    document.querySelector(selector).innerHTML = tpl(data);
}

Compile the template

browserify - t vashify build.js > compiled.js

And the calling it like this:

....
$.ajax({
    ....
    success: function(data) {
        compiledTemplates.myTemplate(data, "#my-id");
    }
});
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

1 participant