Skip to content

Commit

Permalink
Merge pull request #28 from tbrlpld/minor-readme-fixes
Browse files Browse the repository at this point in the history
Minor readme fixes
  • Loading branch information
tbrlpld authored Feb 23, 2024
2 parents 108480e + a058829 commit 36751dd
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Laces
# Laces 👟

[![License: BSD-3-Clause](https://img.shields.io/github/license/tbrlpld/laces)](https://github.com/tbrlpld/laces/blob/main/LICENSE)
[![PyPI version](https://img.shields.io/pypi/v/laces)](https://pypi.org/project/laces/)
Expand Down Expand Up @@ -219,9 +219,10 @@ A couple more examples of how components can be used can be found [below](#patte
#### Using the parent context

You may have noticed in the above examples that the `render_html` and `get_context_data` methods take a `parent_context` argument.
This is the context of the template that is calling the component.
This is the context of the template that is rendering the component.
The `parent_context` is passed into the `render_html` method by the `{% component %}` template tag.
In the default implementation of the `render_html` method, the `parent_context` is then passed to the `get_context_data` method.

In the default implementation of the `render_html` method, the `parent_context` is passed to the `get_context_data` method.
The default implementation of the `get_context_data` method, however, ignores the `parent_context` argument and returns an empty dictionary.
To make use of it, you will have to override the `get_context_data` method.

Expand Down Expand Up @@ -289,7 +290,7 @@ Specifically, the keywords `with`, `only` and `as` are supported, similar to how

#### Provide additional parent context variables with `with`

You can pass additional parent context variables to the component using the keyword `with`:
You can pass additional parent context variables to the component using the `with` keyword.

```html+django
{% component welcome with name=request.user.first_name %}
Expand All @@ -301,7 +302,7 @@ For more information see the above section on the [parent context](#using-the-pa

#### Limit the parent context variables with `only`

To limit the parent context variables passed to the component to only those variables provided by the `with` keyword (and no others from the calling template's context), use `only`:
To limit the parent context variables passed to the component to only those variables provided by the `with` keyword (and no others from the calling template's context), use `only`.

```html+django
{% component welcome with name=request.user.first_name only %}
Expand All @@ -311,7 +312,7 @@ To limit the parent context variables passed to the component to only those vari

#### Store the rendered output in a variable with `as`

To store the component's rendered output in a variable rather than outputting it immediately, use `as` followed by the variable name:
To store the component's rendered output in a variable rather than outputting it immediately, use `as` followed by the variable name.

```html+django
{% component welcome as welcome_html %}
Expand Down Expand Up @@ -367,7 +368,7 @@ Once you have defined the assets on the component in one of the two ways above,
This, again, works in the same way as it does for Django form widgets.
The component instance will have a `media` property which returns an instance of the `django.forms.Media` class.
This is the case, even if you used the nested `Media` class to define the assets.
The [string representation of a `Media` objects](https://docs.djangoproject.com/en/5.0/topics/forms/media#s-media-objects) are the HTML declarations to include the assets.
The [string representation of `Media` objects](https://docs.djangoproject.com/en/5.0/topics/forms/media#s-media-objects) are the HTML declarations to include the assets.

In the example home template from above, we can output the component's media declarations like so:

Expand Down

0 comments on commit 36751dd

Please sign in to comment.