Expand my Community achievements bar.

SOLVED

How to compare strings in sightly?

Avatar

Level 1

Hi Everyone, 

I need help with comparing string data using sightly : data-sly-test Please help me if you know how to do that. This is what I tried but didn't worked.

 

     <sly  data-sly-test.var1="${abc.xyz.name}"></sly>
     <sly  data-sly-test.var2=" ${'abc.xyz.lmn' @i18n}"></sly>
     <sly  data-sly-test.var3=" ${'abc.xyz.jkl' @i18n}"></sly>


${var1}

${var2}

                            <div data-sly-test="${var1 == var2}">TEST</div>
                            <div data-sly-test="${var1 == var3}">NOT TEST</div>

 

 

I got Output as values of var1 & 2 but no output for data-sly-test.

1 Accepted Solution

Avatar

Correct answer by
Administrator

Hi 

I Just tried the following:-

<div data-sly-test.var1="${currentPage.title}">
            Test 1
    </div>
    <div data-sly-test.var2="${currentPage.title}">
            Test 1.1
    </div>
    ${var1}
    ${var2}

    <div data-sly-test="${var1==var2}">
            Test 2
    </div>

Output is:- 

Test 1
Test 1.1
HTLMFPage HTLMFPage
Test 2
 

~kautuk



Kautuk Sahni

View solution in original post

4 Replies

Avatar

Correct answer by
Administrator

Hi 

I Just tried the following:-

<div data-sly-test.var1="${currentPage.title}">
            Test 1
    </div>
    <div data-sly-test.var2="${currentPage.title}">
            Test 1.1
    </div>
    ${var1}
    ${var2}

    <div data-sly-test="${var1==var2}">
            Test 2
    </div>

Output is:- 

Test 1
Test 1.1
HTLMFPage HTLMFPage
Test 2
 

~kautuk



Kautuk Sahni

Avatar

Administrator

Also have a look at this post :- http://stackoverflow.com/questions/30388281/how-to-say-if-something-equals-to-a-string-in-sightly

//This talks about "How to say if something equals to a string in Sightly?"

 

PS:- HTML Template Langue formerly known as sightly. 

~kautuk



Kautuk Sahni

Avatar

Level 3

kautuksahni​ : Is there any way i can check in htl if the page URL contain specific path.

Avatar

Level 1

I had the same query. Please help if there's an efficient way to do that.