Expand my Community achievements bar.

SOLVED

Access Sightly Variable In HandleBars

Avatar

Level 5

Hi,

I have the html file in which I am getting the variable as using below statement:

<sly data-sly-test.myVal=${some exp} />

And I want to use myVal in the hbs template under same file like below.

{{#each Obj}}

     {{#if myVal == 'bla'}}

          <img/>

     {{}}

{{/each}}

Thanks,

1 Accepted Solution

Avatar

Correct answer by
Employee

I don't think the contexts here are shared. So perhaps what you can do is to write JS-vars, and use these in handlebars?

View solution in original post

4 Replies

Avatar

Correct answer by
Employee

I don't think the contexts here are shared. So perhaps what you can do is to write JS-vars, and use these in handlebars?

Avatar

Level 2

Hi,

You can use the sightly variable in the handlebars by adding @context='scriptString', as shown in the below example

{{#if ${myVal ==  'bla' @context='scriptString'}}}

              //something

            {{/if}}

Avatar

Employee

This to me looks not like a valid syntax.

Avatar

Level 2

I have tested it. This is working fine for me.