adobe / htl-spec

HTML Template Language Specification
Apache License 2.0
280 stars 146 forks source link

Clarification of template identifiers #66

Closed lachlanmcdonald closed 6 years ago

lachlanmcdonald commented 6 years ago

Hi,

I have a few questions regarding edge-cases for data-sly-template that I was hoping to have clarified:

Can templates be called prior to declaration

Would the following render bar or throw an error?

The spec states:

The identifier set by the data-sly-template block element is global and available no matter if it's accessed before or after the template's definition

Which I assume also means that the template function is global?

<div data-sly-call="${foo}"></div>
<template data-sly-template.foo>bar</template>

If templates are global, would the following return bar, xyz or throw an error?

<div data-sly-call="${foo}"></div>
<template data-sly-template.foo>bar</template>
<template data-sly-template.foo>xyz</template>

Can templates be referred to by a string

Would the following return foo or throw an error?

<div data-sly-call="${ true ? "foo" : "bar"  }"></div>
<template data-sly-template.foo>foo</template>
<template data-sly-template.bar>bar</template>

Output of template identifier?

What is output by ${foo} in the snippet below?

${foo}
<template data-sly-template.foo>bar</template>
${foo}
tripodsan commented 6 years ago

Can templates be called prior to declaration

IMO, templates are effectively compiled into functions. most languages (java, javascript, c, c++) allow to call functions or methods out-of-order. also, the wording of the spec supports this. however, practically, it is nicer code if you declare the templates before they are used.

Can templates be referred to by a string

yes. by any expression.

Output of template identifier?

how about the name of the template? so just foo in your example ?

lachlanmcdonald commented 6 years ago

Excellent, thanks @tripodsan .

Does this mean that we'd expect:

<template data-sly-template.foo>foo</template>
${foo == 'foo'}

To evaluate as true?