I have found two threads related to the above topic:
However, the following snippet
<script src="js/jsrender.js"></script>
<script type="text/javascript">
var myJsRender = $.noConflict();
</script>
results in:
ReferenceError: $ is not defined
What I am trying to achieve here is to run JsRender regardless of whether
- jQuery and/or
- another instance of JsRender
is loaded on the very same page. Why: Chances are that another plug-in loads JsRender as well.
What am I missing here?
At the time of those issues, JsRender created a global
window.$
if jQuery was not loaded, but gave you a$.noConflict()
method that told JsRender not to to overridewindow.$
, in case another library was using it.But JsRender behavior has been modified since then so that it does not redefine
$
at all. Instead, if jQuery is loaded it adds methods to$
, such as$.render
,$.templates
,$.views.converters
... and if jQuery is NOT loaded, it creates awindow.jsviews
global, and uses that instead of$
- so you havejsviews.render
,jsviews.templates
,jsviews.views.converters
etc.So for example, if you want to call the render method without knowing whether jQuery is loaded or not, you can write:
or if you don't want to use
$
- in case some library other than jQuery is using it, you can write:I'll update those issues to include this information...