diff --git a/dev/concepts/advanced/component_context_scope/index.html b/dev/concepts/advanced/component_context_scope/index.html index 37ee9a1b..303ca886 100644 --- a/dev/concepts/advanced/component_context_scope/index.html +++ b/dev/concepts/advanced/component_context_scope/index.html @@ -11,7 +11,7 @@ return { "date": outer_fields, } -
However, as a best practice, it’s recommended not to rely on accessing the outer context directly through self.outer_context
. Instead, explicitly pass the variables to the component. For instance, continue passing the variables in the component tag as shown in the previous examples.
django_components supports both Django and Vue-like behavior when it comes to passing data to and through components. This can be configured in context_behavior.
This has two modes:
"django"
The default Django template behavior.
Inside the {% fill %}
tag, the context variables you can access are a union of:
{% with %}
tags.{% for ... %}
) that the {% fill %}
tag is part of.Component.get_template_data()
of the component that owns the fill tag."isolated"
Similar behavior to Vue or React, this is useful if you want to make sure that components don't accidentally access variables defined outside of the component.
Inside the {% fill %}
tag, you can ONLY access variables from 2 places:
{% for ... %}
) that the {% fill %}
tag is part of.Component.get_template_data()
of the component which defined the template (AKA the "root" component).Warning
Notice that the component whose get_template_data()
we use inside {% fill %}
is NOT the same across the two modes!
Consider this example:
However, as a best practice, it’s recommended not to rely on accessing the outer context directly through self.outer_context
. Instead, explicitly pass the variables to the component. For instance, continue passing the variables in the component tag as shown in the previous examples.
django_components supports both Django and Vue-like behavior when it comes to passing data to and through components. This can be configured in context_behavior.
This has two modes:
"django"
The default Django template behavior.
Inside the {% fill %}
tag, the context variables you can access are a union of:
{% with %}
tags.{% for ... %}
) that the {% fill %}
tag is part of.Component.get_template_data()
of the component that owns the fill tag."isolated"
Similar behavior to Vue or React, this is useful if you want to make sure that components don't accidentally access variables defined outside of the component.
Inside the {% fill %}
tag, you can ONLY access variables from 2 places:
{% for ... %}
) that the {% fill %}
tag is part of.Component.get_template_data()
of the component which defined the template (AKA the "root" component).Warning
Notice that the component whose get_template_data()
we use inside {% fill %}
is NOT the same across the two modes!
Consider this example:
Then if get_template_data()
of the component "my_comp"
returns following data:
Then the template will be rendered as:
Because variables "my_var"
and "cheese"
are searched only inside RootComponent.get_template_data()
. But since "cheese"
is not defined there, it's empty.
Info
Notice that the variables defined with the {% with %}
tag are ignored inside the {% fill %}
tag with the "isolated"
mode.