5

In a display template (a filter item template to be precise), I observe a weird behavior with for loops.

Let's say my template consists in:

    <div id="CustomRefinement">
<!--#_

for(var x=0;x<10;x++ ){

}
for(var y=0;y<10;y++){

}    

_#-->
    </div>

It's transformed like this:

for(var x=0;x<10;x++ ){

}
for(var y="0;y<10;y++){"

}   

(notice the quotes in the 2nd for loop)

However, if I add spaces like this :

    <div id="CustomRefinement">
<!--#_

for(var x=0 ; x < 10 ; x++ ){

}
for(var y=0 ; y < 10 ; y++){

}   

_#-->
    </div>

It's transformed as:

for(var x=0 ; x < 10 ; x++ ){

}
for(var y=0 ; y < 10 ; y++){

}   

Is there any reason explaining this behavior? Is there any other subtility to be aware of?

1 Answer 1

2

I can replicate this behaviour with

if(2<1){}

While a space after < runs fine

if(2< 1){}

Looks like a bug with the < in the parser that extracts the javascript from the HTML comments

Because

if(1>2){}

runs fine

"Seattle, we have a problem"

Your statement can be duct-taped by placing the value inside round brackets

for(var x=0;x<(10);x++){}

I presume the bug has to do with an incorrect Regular Expression

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.