Skip to content

Component Initial HTML #27

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

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ In context this will look a bit like the following...
</html>
```

Keyworded parameters that can also be passed in include `class="example"` and `initial_html="example.html"`

## `example_app/views.py`

You can then serve `your-template.html` from a view just
Expand Down
2 changes: 1 addition & 1 deletion src/django_idom/templates/idom/component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load static %}
<div id="{{ idom_mount_uuid }}" class="{{ class }}"></div>
<div id="{{ idom_mount_uuid }}" class="{{ class }}">{% if initial_html %}{% include initial_html %}{% endif %}</div>
<script type="module" crossorigin="anonymous">
import { mountViewToElement } from "{% static 'js/django-idom-client.js' %}";
const mountPoint = document.getElementById("{{ idom_mount_uuid }}");
Expand Down
2 changes: 2 additions & 0 deletions src/django_idom/templatetags/idom.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ def idom_component(_component_id_, **kwargs):
_register_component(_component_id_)

class_ = kwargs.pop("class", "")
initial_html = kwargs.pop("initial_html", "")
json_kwargs = json.dumps(kwargs, separators=(",", ":"))

return {
"class": class_,
"initial_html": initial_html,
"idom_websocket_url": IDOM_WEBSOCKET_URL,
"idom_web_modules_url": IDOM_WEB_MODULES_URL,
"idom_ws_max_reconnect_delay": IDOM_WS_MAX_RECONNECT_DELAY,
Expand Down