Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,26 @@ WEBPACK_LOADER = {

If you need the URL to an asset without the HTML tags, the `get_files` template tag can be used. A common use case is specifying the URL to a custom css file for a Javascript plugin.

`get_files` works exactly like `render_bundle` except it returns a list of matching files and lets you assign the list to a custom template variable. For example:
`get_files` works exactly like `render_bundle` except it returns a list of matching files and lets you assign the list to a custom template variable.

Each object in the returned list has 2 properties:
1. `name`, which is the name of a chunk from the stats file;
2. `url`, which can be:
1. The `publicPath` if the asset has one;
2. The `path` to the asset in the static files storage, if the asset doesn't have a `publicPath`.

For example:

```HTML+Django
{% load get_files from webpack_loader %}

{% get_files 'editor' 'css' as editor_css_files %}
CKEDITOR.config.contentsCss = '{{ editor_css_files.0.publicPath }}';
CKEDITOR.config.contentsCss = '{{ editor_css_files.0.url }}';

<!-- or list down name, path and download url for every file -->
<!-- or list down name and url for every file -->
<ul>
{% for css_file in editor_css_files %}
<li>{{ css_file.name }} : {{ css_file.path }} : {{ css_file.publicPath }}</li>
<li>{{ css_file.name }} : {{ css_file.url }}</li>
{% endfor %}
</ul>
```
Expand Down
2 changes: 1 addition & 1 deletion webpack_loader/templatetags/webpack_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_files(bundle_name, extension=None, config='DEFAULT'):
Example usage::

{% get_files 'editor' 'css' as editor_css_chunks %}
CKEDITOR.config.contentsCss = '{{ editor_css_chunks.0.publicPath }}';
CKEDITOR.config.contentsCss = '{{ editor_css_chunks.0.url }}';

:param bundle_name: The name of the bundle
:param extension: (optional) filter by extension
Expand Down