Closed nerdoc closed 6 months ago
Hey,
You should already be able to do that without having to override the get_context_data()
method inside the child component, you just have to add the tag
to the context in the parent (Link
), e.g.:
@component.register("link")
class Link(component.Component):
tag = "a"
def get_context_data(self, **kwargs) -> dict:
context = super().get_context_data(**kwargs)
context.update(
{
"url": self.attributes.pop("url"),
"htmx": self.attributes.pop("htmx", None),
"tag": self.tag,
}
)
return context
@component.register("linkbutton")
class LinkButton(Link):
tag = "button"
Hm. OMG, did I really miss that? That's simple Python 1x1. Sorry for the spam :man_facepalming: .
Hi. Thanks for this awesome library.
What do you think of easily adding class attributes to the component, those being available automatically in the template?
This could lead to very cool things like:
In my code this leads to significant less duplication. But I have to write the tag into the
get_context_data()
and make a super() call for inheriting. Class attributes would be inherited automatically.The only thing that speaks agains that is to keep class attributes for "reactive" values later... ?