Closed struct78 closed 4 years ago
I think this should work. if not, this is a bug.
I think this should work. if not, this is a bug.
Do you need anything from me to be able to flag it as a bug and get it fixed?
Do you need anything from me to be able to flag it as a bug and get it fixed?
I'll look into it this or next week. Pull requests welcome, of course :-)
Currently we only support static external templates, Since we can't compile them at runtime. Also, there is no way to pre-compile them, other than reference them statically.
but with your static example, it works for me. but I don't see this:
<div>src/components/button/button.htl</div>
if you really want dynamic rendering of components based on a variable, you can create some sort of template library: data
{
component: {
path: 'template_spec/button.htl',
name: 'button',
data: {
text: 'This is a button',
},
},
page: {
title: 'This is the title',
},
}
button.htl
<template data-sly-template.button="${@ data}">
<button>${data.text}</button>
</template>
heading.htl
<template data-sly-template.heading="${@ data}">
<h1>${data.text}</h1>
</template>
library.htl
<sly data-sly-use.comps="./button.htl"/>
<sly data-sly-use.comps="./heading.htl"/>
<template data-sly-template.lib="${@ name, data}">
<sly data-sly-test="${name == 'button'}" data-sly-call="${lib.comps.button @ data=data}" />
<sly data-sly-test="${name == 'heading'}" data-sly-call="${lib.comps.heading @ data=data}" />
</template>
template
<sly data-sly-use.lib="./library.htl"/>
<h1>${page.title}</h1>
<!-- here comes the heading -->
<div data-sly-call="${lib.lib @ name='heading', data=component.data}"></div>
<!-- here comes the button -->
<div data-sly-call="${lib.lib @ name=component.name, data=component.data}"></div>
output
<h1>This is the title</h1>
<!-- here comes the heading -->
<div>
<h1>This is a button</h1>
</div>
<!-- here comes the button -->
<div>
<button>This is a button</button>
</div>
I am writing a HTL template that receives a data object with information about the page, and a component to include.
data passed to compiler:
button.htl
template.htl
When I try to use a dynamic value, I get this error:
So the path to the component is correct.
When I use a static value, I get this.
Is this supported? If not, is there another way I can include a HTL file and pass data to it without using
use
?