We're storing all our page content and blog posts etc inside WordPress, using its API to render the data in our Aurelia app. This is working well;
<div class="excerpt" innerhtml.bind="post.excerpt.rendered"></div>
Authors would now like to be able to link to popups or use route-href
or other custom Aurelia attributes from within their blog posts, however code added to the page using innerhtml.bind
doesn't get parsed by Aurelia.
I love that a normal <a href="...">
"just works" in Aurelia - but we have plenty of custom attributes (like <button popup="name-of-popup">...</button>
which can't be used by authors.
How can we overcome this?
Edit: With the comments from @bigopon I've started on something, but still can't quite get it to work. Either I suck at searching or the documentation is a little lacking on the TemplatingEngine.enhance()
method, but I tried creating a custom attribute like this:
import {Aurelia, inject, TemplatingEngine} from 'aurelia-framework';
@inject(Element, Aurelia, TemplatingEngine)
export class AureliaEnhanceCustomAttribute {
constructor (el, aurelia, templatingEngine) {
this.el = el;
this.aurelia = aurelia; // NOTE: I've never done this before - is it even correct?
this.templatingEngine = templatingEngine;
}
attached () {
this.el.innerHTML = this.value;
// NOTE: Without checking for this we get an endless loop of attached() calls
if (!this.el.classList.contains('au-target')) {
this.templatingEngine.enhance({
element: this.el,
container: Aurelia.container, // NOTE: I'm guessing here
resources: Aurelia.resources, // NOTE: Same here, but I need all my global resources to be available inside the enhanced element too
bindingContext: {} // NOTE: Not sure what to pass in here at all.. :/
});
}
}
}
And I'm using it like so:
<div aurelia-enhance.bind="exampleContent"></div>
Where exampleContent
is a string fetched from an API call that could look something like this: '<my-custom-element></my-custom-element><button my-custom-attribute="some-value">Log in</button>'
.
innerhtml
, useTemplatingEngine
compose
/enhance
functions, it will help