Wondering if anyone has tried to turn a piece of markup returned by a server into a reusable Aurelia template?
Let me explain what i'm talking about using a simple example. Let's say a sever renders a page with a list of products for a category. Once a page is loaded i'd like to reuse the markup representing a single product and render a list of products for another category using Aurelia's repeater. I'm looking for a way to enhance a page behaviour without duplicating a markup on client side.
So let's say a server returns something like that:
<ul>
<li class='item'><div>Item content</div></li>
<li class='item'><div>Item content</div></li>
</ul>
I want to turn <li>
element into Aurelia template so i can use the markup to render another list of items using Aurelaia repeater with data loaded dynamically.
I have few ideas how to implement it i.e. extracting the markup from loaded page and passing it to custom-element implementing InlineViewStrategy.
I'm curious how other people would approach that problem.
UPDATE:
So currently I've added a new custom attribute 'as-template' which extracts the markup of decorated element and saves it as a 'item' template. Later on in a custom element I retrieve this saved markup and compile it using ViewCompiler.
<ul>
<li class='item' as-template="item"><div>Item content</div></li>
<li class='item' as-template="item"><div>Item content</div></li>
</ul>
Sample compilation snippet (not my actual code)
let view =viewCompiler.compile('<template>templateMarkup</template>',viewResources).create(container);
view.bind(context);
viewSlot.add(view);
viewSlot.attached();