It'd be nice if could pass attrs from parent to child at compose time #14
Answered
by
jpsca
neilmcguigan
asked this question in
Q&A
-
Say I want a generic container component that can dynamically set args on declared child components like this:
You can do this w Jinja macros (awkwardly):
where parent looks like this:
|
Beta Was this translation helpful? Give feedback.
Answered by
jpsca
Apr 26, 2023
Replies: 1 comment 1 reply
-
You can! But it's barely mentioned in the docs :( (https://jinjax.scaletti.dev/guide/extra/#attrs-methods). <Parent>
<Child __attrs={attrs} />
<Child />
</Parent>
If you only want to pass some arguments (and you know which ones), you can do it like any other value ( <Parent>
<Child title={attrs.get('title') or 'Hello'} />
<Child />
</Parent> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jpsca
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can! But it's barely mentioned in the docs :( (https://jinjax.scaletti.dev/guide/extra/#attrs-methods).
attrs
are the parent attrs__attrs
begins with two underscoresIf you only want to pass some arguments (and you know which ones), you can do it like any other value (
attrs
is similar to a dict)