-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3c1044
commit ff0be30
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Topics | |
slot.md | ||
templates.md | ||
context.md | ||
namespace.md | ||
preview.md | ||
testing.md | ||
articles.md | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# NameSpace | ||
|
||
If your project has many components and want them to be organized in a better way, you can use the namespace feature. | ||
|
||
```bash | ||
├── components | ||
│ └── testapp # this is the namespace | ||
│ └── example | ||
│ ├── example.html | ||
│ └── example.py | ||
``` | ||
|
||
```python | ||
from django_viewcomponent import component | ||
|
||
|
||
@component.register("testapp.example") | ||
class ExampleComponent(component.Component): | ||
|
||
template_name = "testapp/example/example.html" | ||
|
||
def __init__(self, **kwargs): | ||
self.name = kwargs.get('name', 'World') | ||
``` | ||
|
||
You can register the component as `testapp.example` | ||
|
||
```html | ||
{% load viewcomponent_tags %} | ||
|
||
{% component 'testapp.example' name="MichaelYin"%} | ||
{% endcomponent %} | ||
``` | ||
|
||
To use the component in Django template, you can use `component 'testapp.example'` | ||
|
||
Notes: | ||
|
||
1. This can help keep the components organized. | ||
2. If you are developing 3-party Django package (`foo`), you can put all components in the `foo` namespace and use them in the package templates, this would not cause conflicts with other components in the project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello, {{ self.name }}!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django_viewcomponent import component | ||
|
||
|
||
@component.register("testapp.example") | ||
class ExampleComponent(component.Component): | ||
template_name = "testapp/example/example.html" | ||
|
||
def __init__(self, **kwargs): | ||
self.name = kwargs.get("name", "World") |