Giter Site home page Giter Site logo

Comments (5)

BorisMoore avatar BorisMoore commented on September 1, 2024

The way to get a script from a server and share across web pages, is to fetch it by an AJAX request, as a string, and use $.template( myTemplateName, templateString ) to compile it. You can then use it by name as in $.render( data, myTemplateName ) or $( containerElement ).link( data, myTemplateName );

Setting src on the script element will only work for loading javascript scripts, not other types of script block content. (Browsers do not support doing so).

from jsviews.

nogece avatar nogece commented on September 1, 2024

Thanks for the hint, I managed to do it with an ajax request. However, that means I always have to have a server running (firefox security model...!). Not ideal for a designer. But I guess there is no other way.

from jsviews.

BorisMoore avatar BorisMoore commented on September 1, 2024

You can add a script reference <script id="movieTemplate" src="t.js"> and have the script contain either the template markup as a string (assigned to a variable), or the compiled template as a function.

from jsviews.

bwalex avatar bwalex commented on September 1, 2024

What is the way of doing this now that the $.template function is gone and the $.templates function seemingly only accepts selectors?

from jsviews.

BorisMoore avatar BorisMoore commented on September 1, 2024

No, $.templates does not only accept selectors. See the demos of JsViews and JsRender, such as:
https://github.com/BorisMoore/jsrender/blob/master/demos/step-by-step/02_compiling-templates-from-strings.html#L29
Also examples in the unit tests:
https://github.com/BorisMoore/jsrender/blob/master/test/unit/jsrender-tests-no-jquery.js#L206

from jsviews.

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.