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

Tag to specify a single target URL #16

Closed
sbaechler opened this issue Sep 7, 2015 · 2 comments
Closed

Tag to specify a single target URL #16

sbaechler opened this issue Sep 7, 2015 · 2 comments

Comments

@sbaechler
Copy link
Contributor

I have a use-case where I need to specify the URL to a generated CSS file within a Javascript options object. I therefore need the publicPath without the HTML tags.

I have created a working implementation here but maybe there is a better way to do it.
https://github.com/sbaechler/django-webpack-loader/blob/tag/webpack_loader/templatetags/webpack_loader.py

I am using the new tag in the CKeditor config. 'editor' is the name of the CSS bundle:

CKEDITOR.config.contentsCss = '{% bundle_item_url 'editor' 'css' %}';
@owais
Copy link
Collaborator

owais commented Sep 7, 2015

Looks good except we should use name of the chunk instead of the positional index. Also, for the sake of consistency, lets name it get_chunks as it is a verb like render_bundle.

{% get_chunks 'editor' 'css' as 'editor_css_chunks' %} would give us a list of all CSS files in the editor chunk as a list referenced by editor_css_chunks. Then users can fetch [0], loop over it or use any custom logic.

I'd also return all information (file name, path, publicPath) as a dict instead of just the URL.

Your use case would look like

{% get_chunks 'editor' 'css' as 'editor_css_chunks' %}
CKEDITOR.config.contentsCss = '{{ editor_css_chunks[0].publicPath }}';

Makes sense?

@sbaechler sbaechler mentioned this issue Sep 8, 2015
Merged
@owais owais closed this as completed Sep 10, 2015
@owais
Copy link
Collaborator

owais commented Sep 10, 2015

@sbaechler Just released 0.2.0 to the cheeseshop. I renamed get_chunks to get_files as chunks could get confused with webpack's chunks. A bundle contains multiple chunks and each chunks contains multiple files.

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

2 participants