Replies: 2 comments 2 replies
-
This would be excellent! |
Beta Was this translation helpful? Give feedback.
-
I think this could be extended further. There are types of components that need context, like containers, and others that don't by default (you can add it using class UserName(BasicComponent):
__extra_context = ["user"]
template = """<div>{{ user.username }}</div>""" There are many components that generally need the request object, the user, or, dependent on your needs, special vars in the template context. This would ease working with it and is analogue to Django's |
Beta Was this translation helpful? Give feedback.
-
The purpose for basic components is to build the "Lego" blocks of a modern web page. nearly all of them need much of the available context, and could be very big, like e.g. UI elements like Bootstrap card elements, an easy
Card
component could look like:Now, when using that component, you have to add the
context: **context
to each and everycard
tag you write. If you forget it, this produces bugs you don't see at once, as django context vars that are referenced, but non-existent, are just empty, and worse, in if clauses, are always false.So in your component usage, a
will just never display anything, because user is not in the context.
I agree that context is a burden for Alpine.js enabled (and stateful) components, but as
BasicComponent
s are stateless, the burden is quite none.So I think that adding all context to BasicComponents per default would be a good way, even if it is not consistent. But, BasicComponents and Components differ anyway, it's all about documentation. And coding is much better with components that help you to write less code.
Ideas?
Beta Was this translation helpful? Give feedback.
All reactions