how to use HTL expressions inside a handlebars template (text/x-handlebars-template)?

Avatar

Avatar
Give Back 10
Level 4
jayv25585659
Level 4

Likes

46 likes

Total Posts

131 posts

Correct reply

0 solutions
Top badges earned
Give Back 10
Validate 25
Validate 10
Validate 1
Contributor 2
View profile

Avatar
Give Back 10
Level 4
jayv25585659
Level 4

Likes

46 likes

Total Posts

131 posts

Correct reply

0 solutions
Top badges earned
Give Back 10
Validate 25
Validate 10
Validate 1
Contributor 2
View profile
jayv25585659
Level 4

19-07-2021

I have an HTL template that contains a handlebars template (<script id="topic-header-base" type="text/x-handlebars-template">).

My problem is that displaying the value of an HTL variable inside a handlebars templates gives me blank. It seems to be the HTL inside the template is ignored.

In my code below: this is what I get on the browser => inside template1 - inside handlebars template - product.year: (product.year is empty/null)

 

Basically I want to use data-sly-test to hide/show pieces of content/information in my handlebars template.

 

here's my full code

 

 

    <sly data-sly-use.make="${'com.myhost.core.impl.view.page.ProductPageHelper'}"></sly>

    <h3>ourside of template - year: ${make.product.year}</h3>
    <sly data-sly-test="${make.product.year > 2020}"><h3>outside of template - greater than 2020</h3></sly>

    <sly data-sly-use.template1="template1.html" data-sly-call="${template1.template @ product=make.product}" data-sly-unwrap></sly>
    <div id="template1-target"></div>

    <script type="text/javascript">
        $( document ).ready(function() {
            $("#template1-target").html(Handlebars.compile($("#template1-base").html())());
        });
    </script>
    contents of template1.html
    <template data-sly-template.template="${@product}">
        <h3>inside template1 -  outside handlebars template - product.year: ${product.year}</h3>

        <sly data-sly-test="${product.year > 2020}"><h3>inside template1 - outside handlebars template - insert-link-here</h3></sly>

        <script id="template1-base" type="text/x-handlebars-template">
            <h3>inside template1 -  inside handlebars template - product.year: ${product.year}</h3>

            <sly data-sly-test="${product.year > 2020}"><h3>inside template1 - inide handlebars template - insert-link-here</h3></sly>
        </script>
    </template>

 

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 5
Level 2
piotrr32520682
Level 2

Likes

7 likes

Total Posts

4 posts

Correct reply

2 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Boost 5
Level 2
piotrr32520682
Level 2

Likes

7 likes

Total Posts

4 posts

Correct reply

2 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Affirm 1
View profile
piotrr32520682
Level 2

19-07-2021

Answers (0)