Skip to content
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

Add new data-alias attribute to make templates work with outside variables #432

Merged
merged 4 commits into from
Mar 30, 2023

Conversation

Dakror
Copy link
Contributor

@Dakror Dakror commented Mar 24, 2023

This PR adds the ability to use templates as reusable components within data-model trees. By wrapping the inline template in an element that defines variable name aliases using data-alias-<new-name>="<data address>", the template can refer to any outside variable by a fixed name.

@Dakror Dakror marked this pull request as draft March 24, 2023 21:57
@Dakror Dakror marked this pull request as ready for review March 24, 2023 22:00
@mikke89 mikke89 added enhancement New feature or request data binding labels Mar 25, 2023
@mikke89
Copy link
Owner

mikke89 commented Mar 26, 2023

I'm not sure I understand the motivation. Why can't we just set the title data variable directly?

@Dakror
Copy link
Contributor Author

Dakror commented Mar 26, 2023

How so? title is not a variable in the original data model. My use case is i define a component to render some form of inventory, but when using the component in different UI scenarios, the variable sourcing the inventory data might have different names

@mikke89
Copy link
Owner

mikke89 commented Mar 28, 2023

Ah, I see. Does it also work as expected when including the template multiple times, possibly with different variables? That sounds pretty useful.

The implementation looks good to me.

Are you able to update the documentation with a small example? Thanks!
https://mikke89.github.io/RmlUiDoc/pages/data_bindings/views_and_controllers.html

@mikke89 mikke89 merged commit 4db7a3b into mikke89:master Mar 30, 2023
@mikke89
Copy link
Owner

mikke89 commented Mar 30, 2023

Looks good, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data binding enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants