x => x.size
x => x.block ? 'btn-block' : ''
(x) => x.getName()
Then, for variable parts, we remove the lambda part (VARIABLE => VARIABLE.) by regex via parse function. Finally, an HTML is created according to the acceptable standards for the Aurelia template engine.
The generic parameter in this function is actually your view-model.
bs-button-template.ts
import { html } from './strongly-typed-template';
// BootstrapButton is my view-model
export const buttonTemplate = html<BootstrapButton>`
<button class="btn btn-primary btn-${x => x.size} ${x => x.block ? 'btn-block' : ''}" ref="bsButtonTemplate">
${(x) => x.getName()}
</button>
`;
Now, we have to introduce this strongly-typed template to Aurelia via template option.
bs-button.ts
import { buttonTemplate } from "./bs-button-temlate";
@customElement({ name: "bs-button", template: buttonTemplate /* HERE */ })
export class BootstrapButton /* view-model */ {
@bindable({ mode: BindingMode.toView }) public size: string;
@bindable({ mode: BindingMode.toView }) public block: boolean;
getName() {
return "Primary Button";
}
}