-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make component_id available in component's template context #389
Comments
BTW, maybe |
@nerdoc Good idea! That should be straight-forward to add it in. I'll do it for the next release. 👍 |
Add this is in 1dd2678. It will go live in the next release. |
Should be fixed in 0.44.1 which I just deployed: https://pypi.org/project/django-unicorn/0.44.1/. |
Hmmm. Using 0.44.1, the values are available under ID: {{ unicorn.component_id }}<br/>
Name: {{ unicorn.component_name }}<br/>
Key: {{ unicorn.component_key }}<br/> produces:
What I need here (and I suppose most of the people needing this feature, too...?) is, to use the So a <input
id="{{ unicorn.component_id }}"
name="{{ unicorn.component_name }}"
...
> is not possible here. I know - if you replace each ./: with an unterline or hyphen, it would be possible, but then the strings would not be tracable back to their origin's component ID... I think you have to decide - I for myself would even go so far to change names and ids within Unicorn to HTML-usable ones, meaning getting rid of the colons and dots...? |
A possible (quick & dirty) solution would be replacing the 2 lines in "component_id": self.component_id.replace(":","_").replace(".","_"),
"component_name": self.component_name.replace(":","_").replace(".","_"), |
Ok, I totally forgot about nested components. That's an internal identifier, so I could potentially change the colon to a pipe |
No, pipe is as good as colon. So if you need these colons as separators internally, the HTML ids could be "shadows" of them, and don't need to be reflected back into python code any more, right. What you have to think about is nesting, yes: if some component wants to change data in the parent's backend, it can use So maybe it is better to keep them "in sync" and use consistent names. |
Sometimes you have to create child components with need of sub HTML tags with certain IDs. It would come handy to know the
ocmponent_id
in the template, to create things likeATM this is only possible if you save it in a normal attribute, or save it in a "readonly" attribute like
_id
in__init__()
, and overrideget_context_data
to include this attr in the context.Would you mind to add
component_id
to the general included context attrs?The text was updated successfully, but these errors were encountered: