-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow user defined tags for js injection #1234
Conversation
Failing test is also failing for me locally in master branch...
|
Hey @gnulnx you can just turn of With To add all head tags (meta tags and styles) you can write:
To add all body tags (scripts) you can write:
Please let me know if that helps you |
@jantimon Yes the lodash template tags work and this is what I've been doing for a year or so. I just found it kinda cumbersome to have to add that much boiler plate to each template and figured if we could insert into the head or body it should be straight forward to insert at any tag and not have to add the full lodash boiler plate to each injection point. |
@gnulnx you can keep the (No need to disable
{% block html %}
<!DOCTYPE html>
<html {% block html_tag_attributes %}{% endblock %}>
<head>
{% block head %}
<meta charset="utf-8">
{% endblock %}
</head>
<body {% block body_tag_attributes %}{% endblock %}>
{% block body %}
{% block content %}{% endblock %}
{% endblock %}
</body>
</html>
{% endblock %}
{% extends "base.html" %}
{% load static %}
{% block html %}
<!DOCTYPE html>
<html {% block html_tag_attributes %}{{ block.super }}{% endblock %}>
<head>
{% block head %}{{ block.super }}{% endblock %}
</head>
<body {% block body_tag_attributes %}{{ block.super }}{% endblock %}>
{% block body %}{{ block.super }}{% endblock %}
</body>
</html>
{% endblock %}
{% extends "bundles/webpack/home_page.html" %}
{% block content %}
Adding content here...
{% endblock %} You don't need to create multiple templates for html-webpack-plugin, create only one by extending from the point your django pages start diverging, then continue extending from the webpack generated templates to your final django page templates. Example: Let's say you have two pages: "Home" and "About" that share the same "layout"
You will get two generated templates that you can extend:
Note: the links in the injected tags can be easily converted to django static tempate tag format, ie: |
Provide support for injection of JS assets into custom tags. Currently the html-webpack-plugin will insert into the end of the head or body section depending upon the inject setting. This PR provides support to allow a user to define a different element to insert the script tags into.
Reasoning behind this is often times template engines will build upon base templates. For instance in a django application a user often defines a base.html template that would define the entire head and body sections and then provide something like a content {% block content %}{% endblock %}. The idea being that the user would then extend this base template into say home.html, about_us.html, etc.
The problem is that webpack sees the html before the other the django templating system (which is runtime). It is currently possible to have webpack insert all js into the base.html template. However, this is not desierable. In a multiplage web application each page is likely to contain it's own JS code.
With this pr the user can now do something like this in weback.conf
Then in any templates they want to inject js into they would simply add their custom tag to the end.