Is there a way to create an element which uses the compose templating construct to dynamically select elements to compose? I have made this in an app, but would like to share this among several apps.
My first guess is that it’s not possible, but if there’s a way, surely here is the place to discover it.
Here’s the case: there are two apps, one for defining forms with some specific fields (like those form builders from wordpress). The other app renders the forms using the definitions.
Both have to render the forms: the first for testing how the form looks and works and the second to present it to the user.
First temptation is to use components, but to choose the name of the components based on data seems unfeasible.
For this my solution is that for each type of element in the form there will be a view-model with a view, so we can include them with the compose clause.
This works fine as ever, though as I need to share this among two apps, my idea was to make a plugin for this.
When including these views and viewmodels from the plugin, I couldn’t instruct aurelia how to find them.
ok thx for the clarification, so essentially an if you’d like to say admin backstore abd a frontend app. using compose you’d most likely just have a couple of vms and views as the forms are rendered dynamically I guess.
so your plugin would than host the vms/views and register them during plugin config globally. now bith apps using your plugin would immediately see them.
if you follow the official docs Write New Plugin | Aurelia youll see how to define those in the plugins configure method
so your plugin would than host the vms/views and register them during plugin config globally. now bith apps using your plugin would immediately see them.
This doesn’t seem to be the case. vms/views to be included with compose are loaded looking for them in the filesystem, not in the global resources registry.
What you are stating is true for components, not for “simple” vms/vm pairs loaded using compose.
Maybe I am wrong, but this is the struggle that I am trying to overcome.
ok yeah thats a bit different if not using webpack. hmm what comes to my mind is to define the template in the view using inlineView | Aurelia . while its not that nice of a separation, it would circumvent the need to load resources on demand.
the difference is that your compose wouldnt anylonger have a view attribute thus nothing that needs the loader. ViewModels should be found via their module, means also when the are registered globally in the plugin.