# Using compose in a plugin

**URL:** <https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546>\
**Category:** Help Requests\
**Created:** [January 6, 2022, 12:16am UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546 "2022-01-06T00:16:36Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ormasoftchile](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ormasoftchile/32/340_2.png) [@ormasoftchile](https://discourse.aurelia.io/u/ormasoftchile)\
**Post date:** [January 6, 2022, 12:16am UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/1 "2022-01-06T00:16:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zewa666](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/zewa666/32/19_2.png) [@zewa666](https://discourse.aurelia.io/u/zewa666)\
**Post date:** [January 6, 2022, 6:13am UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/2 "2022-01-06T06:13:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ormasoftchile](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ormasoftchile/32/340_2.png) [@ormasoftchile](https://discourse.aurelia.io/u/ormasoftchile)\
**Post date:** [January 6, 2022, 12:02pm UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/3 "2022-01-06T12:02:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zewa666](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/zewa666/32/19_2.png) [@zewa666](https://discourse.aurelia.io/u/zewa666)\
**Post date:** [January 6, 2022, 6:02pm UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/4 "2022-01-06T18:02:13Z")

</div>

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](http://aurelia.io/docs/plugins/write-new-plugin#structure-of-plugin) youll see how to define those in the plugins configure method

---

<div class="post-metadata">

**Author:** ![ormasoftchile](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ormasoftchile/32/340_2.png) [@ormasoftchile](https://discourse.aurelia.io/u/ormasoftchile)\
**Post date:** [January 6, 2022, 6:17pm UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/5 "2022-01-06T18:17:56Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![MaximBalaganskiy](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/maximbalaganskiy/32/831_2.png) [@MaximBalaganskiy](https://discourse.aurelia.io/u/MaximBalaganskiy)\
**Post date:** [January 6, 2022, 8:46pm UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/6 "2022-01-06T20:46:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ormasoftchile](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ormasoftchile/32/340_2.png) [@ormasoftchile](https://discourse.aurelia.io/u/ormasoftchile)\
**Post date:** [January 6, 2022, 8:54pm UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/7 "2022-01-06T20:54:08Z")

</div>

Hi, Maxim. Thank you.

In this project I am using Alameda!

Regards.

---

<div class="post-metadata">

**Author:** ![MaximBalaganskiy](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/maximbalaganskiy/32/831_2.png) [@MaximBalaganskiy](https://discourse.aurelia.io/u/MaximBalaganskiy)\
**Post date:** [January 6, 2022, 8:58pm UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/8 "2022-01-06T20:58:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ormasoftchile](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ormasoftchile/32/340_2.png) [@ormasoftchile](https://discourse.aurelia.io/u/ormasoftchile)\
**Post date:** [January 6, 2022, 10:04pm UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/9 "2022-01-06T22:04:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zewa666](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/zewa666/32/19_2.png) [@zewa666](https://discourse.aurelia.io/u/zewa666)\
**Post date:** [January 7, 2022, 5:45am UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/10 "2022-01-07T05:45:12Z")

</div>

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](https://aurelia.io/docs/api/templating/function/inlineView/) . while its not that nice of a separation, it would circumvent the need to load resources on demand.

---

<div class="post-metadata">

**Author:** ![ormasoftchile](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ormasoftchile/32/340_2.png) [@ormasoftchile](https://discourse.aurelia.io/u/ormasoftchile)\
**Post date:** [January 7, 2022, 4:24pm UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/11 "2022-01-07T16:24:43Z")

</div>

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

Thank you

---

<div class="post-metadata">

**Author:** ![zewa666](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/zewa666/32/19_2.png) [@zewa666](https://discourse.aurelia.io/u/zewa666)\
**Post date:** [January 7, 2022, 10:06pm UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/12 "2022-01-07T22:06:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ormasoftchile](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ormasoftchile/32/340_2.png) [@ormasoftchile](https://discourse.aurelia.io/u/ormasoftchile)\
**Post date:** [January 7, 2022, 11:11pm UTC](https://discourse.aurelia.io/t/using-compose-in-a-plugin/4546/13 "2022-01-07T23:11:51Z")

</div>

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

Thanks for the guidance, Vildan.
