mirror of
https://github.com/django-components/django-components.git
synced 2025-08-31 11:17:21 +00:00
First description of how the django-components could work.
This commit is contained in:
parent
b46b1d87f7
commit
0f69d431ba
1 changed files with 34 additions and 0 deletions
34
README.md
34
README.md
|
@ -1,2 +1,36 @@
|
|||
# django-components
|
||||
A way to create simple reusable template components in Django.
|
||||
|
||||
# Installation
|
||||
```pip install django-components``` (NOTE: Does not work yet)
|
||||
|
||||
# Usage
|
||||
|
||||
Start by creating a Component by inheriting from the Component class. Don't forget to register the component so that it's available in the templates.
|
||||
|
||||
```python
|
||||
from django_components import component
|
||||
|
||||
class Calendar(component.Component):
|
||||
def context(self, date):
|
||||
return {
|
||||
"date": date,
|
||||
}
|
||||
|
||||
class Media:
|
||||
template = "[your app]/components/calendar/calendar.html"
|
||||
css = {'all': ('[your app]/components/calendar/calendar.css',)}
|
||||
js = ('[your app]/components/calendar/calendar.js',)
|
||||
|
||||
component.register(name="calendar", component=Calendar)
|
||||
```
|
||||
|
||||
In your templates, use your component by first importing the django_components tag library, and then using the component_dependencies and component tags to render the component to the page.
|
||||
|
||||
```htmldjango
|
||||
{% load components %}
|
||||
{% block extra_media %}{% component_dependencies %}{% endblock %}
|
||||
{% block main %}
|
||||
{% component name="calendar" date=custom_date %}
|
||||
{% endblock %}
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue