mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 14:28:18 +00:00
refactor: Assign content of file from Component.template_file to Component.template (#880)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
8e2428ebd0
commit
1e4b556b4d
12 changed files with 399 additions and 186 deletions
37
docs/templates/reference_signals.md
vendored
Normal file
37
docs/templates/reference_signals.md
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
# Signals
|
||||
|
||||
Below are the signals that are sent by or during the use of django-components.
|
||||
|
||||
## template_rendered
|
||||
|
||||
Django's [`template_rendered`](https://docs.djangoproject.com/en/5.1/ref/signals/#template-rendered) signal.
|
||||
This signal is sent when a template is rendered.
|
||||
|
||||
Django-components triggers this signal when a component is rendered. If there are nested components,
|
||||
the signal is triggered for each component.
|
||||
|
||||
Import from django as `django.test.signals.template_rendered`.
|
||||
|
||||
```python
|
||||
from django.test.signals import template_rendered
|
||||
|
||||
# Setup a callback function
|
||||
def my_callback(sender, **kwargs):
|
||||
...
|
||||
|
||||
template_rendered.connect(my_callback)
|
||||
|
||||
class MyTable(Component):
|
||||
template = """
|
||||
<table>
|
||||
<tr>
|
||||
<th>Header</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Cell</td>
|
||||
</tr>
|
||||
"""
|
||||
|
||||
# This will trigger the signal
|
||||
MyTable().render()
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue