2👍
No you did not misunderstand django-pipeline. You will be able to access the javascript templates in your backbone code. Before I give you the answer lets take a look at what the django-pipeline docs have to say.
Pipeline allows you to use javascript templates along with your javascript views. To use your javascript templates, just add them to your PIPELINE_JS group
So you can add your templates to the pipeline in the settings file like:
PIPELINE_JS = {
'templates': {
'source_filenames': (
'js/templates/**/*.jst',
),
'output_filename': 'js/templates.js'
}
}
Now you have to load these javascript templates in your browser.
Please Note: You have to make sure that you load the templates before your load any javascript code which uses the templates. Otherwise you will get an undefined error.
{% load compressed %}
{% compressed_js 'templates' %}
{% compressed_js 'other_backbone_files' %}
Now the docs say:
It will be available from your javascript code via window.JST
So you will have a global object named ‘window’ and you will be able to access the templates using its ‘JST’ property. The value of the JST property is another javascript object. The properties of this object are the names of your templates and its values are the templates. The names of your templates will depend on how you have included the templates in your settings file.
For example, if in your settings file you included the template as:
'source_filenames': (
'js/templates/**/*.jst',
)
and you had a template at ‘js/templates/app/footer.jst’, you can access the template in your javascript code in the following manner:
template: window.JST['app_footer']
Or if you did something like:
'source_filenames': (
'js/templates/app/*.jst',
)
OR
'source_filenames': (
'js/templates/app/footer.jst',
)
and you had a template at ‘js/templates/app/footer.jst’, you can access the template in your javascript code in the following manner:
template: window.JST['footer']
Notice that you need to include the name of the template from the first ‘*’
If you are still not sure then you can inspect the window.JST object in your javascript console to examine its properties.
If you want to use some other attribute name other than ‘JST’ then you can change it using the following setting in your settings.py
PIPELINE_TEMPLATE_NAMESPACE = 'window.Templates'
Now you can access your templates will be in the window.Templates objects instead of being in window.JST
0👍
Seems you should add also ‘js/backbone/templates/.jst’ as ‘js/backbone/templates/*/*.jst’ will match only templates in subfolder.
- [Answered ]-Tango with django chapter 19 — Adding Inline Category Suggestions
- [Answered ]-Swampdragon settings.js