Template handlebars is not filled even when there is data

2

I am working on a project in Kotlin that generates XML files using templates with Handlebars (in the server side , the version 4.0.6). I have the following class in a .kt file:

class miClase(val codigo: String, val nombre: String?)

And this in a template .hbs:

...
{{#each misClases}}
  <elemento code="{{codigo}}" name="{{nombre}}">
{{/each}}
...

And it works without problems. The XML is generated with a list of elements. Now I have been asked that the part of the template that is generated from a list of miClase should not include empty elements. That is, if the code or name is missing, it will be displayed, but if both are missing, they will not be displayed.

For that I have changed the class to this:

class miClase(val codigo: String, val nombre: String?) {

    var isVisible = true

    init {
        if (codigo.isNullOrEmpty() && nombre.isNullOrEmpty()) {
            isVisible = false
        }
    }
}

And I have changed the template to make it like this:

...
{{#each misClases}}
  {{#if isVisible}}
  <elemento code="{{codigo}}" name="{{nombre}}">
  {{/if}}
{{/each}}
...

Everything seems correct, but the data is not displayed. I have done debug, and I can see that the list of objects is there and that everyone has the property isVisible with the value true so that part of the template should be filled and visible, but it is not.

What happens is not that the values appear empty, but that the elemento is not even loaded directly.

Why does this happen? What is wrong with the code?

    
asked by Alvaro Montoro 05.12.2017 в 22:40
source

1 answer

1

I've been able to solve it in the most weird / silly way: changing the name of the property from isVisible to hasCodeName (although it would be worth another name) and it works.

It seems that isVisible is a reserved word or a method in some of the plugins and dependencies that the project uses (in particular it seems that of Selenium). So I did not take the isVisible of the class, but the isVisible of the dependency and that's why it failed. Changing the name was the solution.

    
answered by 01.02.2018 / 21:58
source