Access Sightly Variable In HandleBars | Community
Skip to main content
New Participant
June 11, 2017
Solved

Access Sightly Variable In HandleBars

  • June 11, 2017
  • 4 replies
  • 3172 views

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,

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Feike_Visser1

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?

4 replies

New Participant
June 12, 2017

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

Feike_Visser1
Employee
June 12, 2017

This to me looks not like a valid syntax.

New Participant
June 12, 2017

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}}

Feike_Visser1
Feike_Visser1Accepted solution
Employee
June 12, 2017

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?