wrabit / django-cotton

Enabling Modern UI Composition in Django
https://django-cotton.com
MIT License
506 stars 20 forks source link

Only isolates context #174

Closed mattbha closed 3 weeks ago

mattbha commented 3 weeks ago

I added the ability to add only to a component to isolate the components context from the parent (similar to what django implements for include: https://docs.djangoproject.com/en/5.1/ref/templates/builtins/#include)

with a simple component:

simple.html

<a class="{{ class|default:"donttouch" }}">test</a>

this component, with parent context {"class":"herebedragons"} will render (as normal) <c-simple /> as <a class="herebedragons">test</a>

whereas <c-simple only /> (with the same parent context {"class":"herebedragons"}) renders as <a class="donttouch">test</a>

I think the tests I added are sufficient but I'm not 100% sure.

mattbha commented 3 weeks ago

if this is accepted we probably should also update the docs.

wrabit commented 3 weeks ago

@mattbha Looks good, thanks - I will line up change to docs