Skip to content

Isolated components (using only) do not receive props correctly #233

@benbacardi

Description

@benbacardi

Unless I'm misunderstanding what's meant to happen, it seems that isolated components specified with only don't receive props correctly when the values of the props come from the parent context.

With a basic view:

def view(request):
    return render(request, "index.html", {"a_string_var": "Hello World"})

And the following basic component:

# bird/basic_component.html
{% bird:prop text %}
<p>Text: {{ props.text }}</p>

Rendered by the following template:

{% bird basic_component text="Hello World" / %}
{% bird basic_component text="Hello World" only / %}
{% bird basic_component text=a_string_var / %}
{% bird basic_component text=a_string_var only / %}

Results in the following HTML:

<p>Text: Hello World</p>
<p>Text: Hello World</p>
<p>Text: Hello World</p>
<p>Text: a_string_var</p>

The final isolated component only receives the stringified name of the variable passed to the prop, not the value of the variable. This feels unhelpful and counter intuitive, and against my understanding of the docs:

When only is used:

  • The component cannot access variables from the parent context
  • Props, slots, and other component-specific context still work normally
  • Default values in the component template will be used when parent context variables are not available

Emphasis mine.

Tested using Django 4.2 (current LTS) and django-bird 0.17.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions