Skip to content
Open
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
12 changes: 8 additions & 4 deletions source/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,18 @@ class HelloWorldView(UnicornView):
name = "World"
```

In file hello-world.html
```html
<!-- hello-world.html -->
<div>
<input unicorn:model="name" type="text" id="text" /><br />
Hello {{ name|title }}
</div>
```

```{warning}
Do not add anything before the <div> . No HTML comment, no tags, no text.
```

`unicorn:model` is the magic that ties the input to the backend component. The Django template variable can use any property or method on the component as if they were context variables passed in from a view. The attribute passed into `unicorn:model` refers to the property in the component class and binds them together.

```{note}
Expand Down Expand Up @@ -143,8 +147,8 @@ class HelloWorldView(UnicornView):
book_ratings = {'excellent': {'title: 'American Gods'}}
```

In file hello-world.html
```html
<!-- hello-world.html -->
<div>
<input unicorn:model="book.title" type="text" id="model" />
<input
Expand Down Expand Up @@ -172,8 +176,8 @@ class HelloWorldView(UnicornView):
books = Book.objects.all()
```

In file hello-world.html
```html
<!-- hello-world.html -->
<div>
<input unicorn:model="books.0.title" type="text" id="text" />
</div>
Expand Down Expand Up @@ -205,8 +209,8 @@ class Author(UnicornField):
author = Author()
```

In file hello-world.html
```html
<!-- hello-world.html -->
<div>
<input unicorn:model="author.name" type="text" id="author_name" />
</div>
Expand Down