Expand my Community achievements bar.

SOLVED

<sly> element in <script> tag not evaluating?

Avatar

Level 3

I have a problem similar to this one: Sightly in &lt;script&gt; tag not evaluating?

In that thread, the problem was that Sightly expressions inside a script element were not being rendered, and the solution was to add @ context = 'scriptString' to the expression.

My situation is a slightly different: Inside my HTML script element, I want to put a Sightly element:

<script id="availabilitiesTemplate" type="text/template" >

    <sly data-sly-include="availabilitiesTemplate.html"></sly>

</script>

But the included file is not rendered to the output.

I suspect this is also a context problem, but I can't find any docs on setting the context on a <sly> element, and none of my experiments have worked. I've tried setting the context:

<script id="availabilitiesTemplate" type="text/template" >

    <sly data-sly-include="${ availabilitiesTemplate.html @ context = 'scriptString' }"></sly>

</script>

I've also tried assigning the template with a data-sly-use expression:

<sly data-sly-use.avail="availabilitiesTemplate.html"></sly>

<script id="availabilitiesTemplate" type="text/template" >

    ${avail @ context='scriptString'}

</script>

Neither of these approaches works either; in all cases the output is

<script id="availabilitiesTemplate" type="text/template" >

</script>

Is there any way to get a <sly> element to render inside a <script> element?

1 Accepted Solution

Avatar

Correct answer by
Level 5

Hi volcohen,

The problem is you are using the whole sightly syntax .

You can try with handlebar use this line to include resource in script.

<script id="my-handlebar-template" type="text/x-handlebars-template" data-sly-include="handlebar.html"></script>

you can get more idea by go through this link How to use Sightly expressions in Handlebar templates, avoiding to explicitly set the context on eac...

View solution in original post

2 Replies

Avatar

Correct answer by
Level 5

Hi volcohen,

The problem is you are using the whole sightly syntax .

You can try with handlebar use this line to include resource in script.

<script id="my-handlebar-template" type="text/x-handlebars-template" data-sly-include="handlebar.html"></script>

you can get more idea by go through this link How to use Sightly expressions in Handlebar templates, avoiding to explicitly set the context on eac...

Avatar

Level 3

That worked perfectly -- thanks!