Using compose in a plugin

Hi guys,

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.

Regards,

Cristian

can you oerhaps describe your use case a little more? what would you like to achieve? how should the plugin (pseudo-code) be consumed?

Hi. Vildan.

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.

Hope this explains a little better the issue.

Regards.

Cristian

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.

Thanks.

@ormasoftchile if you are using webpack use platform.moduleName to include templates in the bundle

Hi, Maxim. Thank you.

In this project I am using Alameda!

Regards.

So you are not bundling your code?
May be use full paths in compose, like “pluginname/views/template.html”

Hi, Maxim.
I am using Alameda which means bundling with a similar way as require, so paths are not an option with that setup.

By now I am considering:

  1. Make a shared folder and (gulp) copy the contents from one folder to the other.
  2. Try with webpack to test it.

Regards.

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.

inlining the views is not an issue. How this would change how the compose statement looks for the viewmodel?

Thank you

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.

Didn´t know that. I will try this soon.

Thanks for the guidance, Vildan.