Template engine: a nesting issue I face



  • Hi,

    I am still wondering if what I found is a valid bug or not.
    When I try to test the template engine using the given example below, it works fine.

    {
        "animals": [
            {
                "name": "Cat",
                "species": "Felis silvestris catus",
                "isHuman": false,
            },
            {
                "name": "Dog",
                "species": "Canis lupus familiaris",
                "isHuman": false,
            },
            {
                "name": "Human",
                "species": "Homo sapiens",
                "isHuman": true
            }
        ],
        "package": {
            "name": "templates.js",
            "author": "psychobunny",
            "url": "http://www.github.com/psychobunny/templates.js"
        },
        "website": "http://burnaftercompiling.com",
        "sayHello": true
    }
    
    <!-- BEGIN animals -->
      {animals.name} is from the species {animals.species}.
    <!-- END animals -->
    

    After that, I had the animals moved under another field 'living' as a child as noted below:

    {
        "living": {
           "animals": [
               {
                "name": "Cat",
                "species": "Felis silvestris catus",
                "isHuman": false,
              }, ....
             ]
      }
    

    For this JSON data, the following doesn't print out anything:

    <!-- BEGIN living.animals -->
      {living.animals.name} is from the species {living.animals.species}.
    <!-- END living.animals -->
    

    Is this a known limitation or a bug? Am I missing something here?

    Thanks


  • Admin

    Does this work?

    <!-- BEGIN animals -->
      {living.animals.name} is from the species {living.animals.species}.
    <!-- END animals -->
    


  • @baris said:

    Does this work?

    <!-- BEGIN animals -->
      {living.animals.name} is from the species {living.animals.species}.
    <!-- END animals -->
    

    Thanks for your reply. I tried it and it works!
    Is that the intended use? What if another 'animals' is also there under a different node within the same json document?


  • Admin

    That is a question for @psychobunny. You can test it quickly by adding another node with an animals array.



  • @baris Thanks anyways.

    Another strange behavior I noticed was that using 'abc2' for array didn't work whereas 'abc' is fine. Putting a number at the end of node name doesn't print out anything though in my testing. Just FYI


  • Admin

    @thinkdiff said:

    You can report bugs you find to the templates.js repo as well. https://github.com/psychobunny/templates.js/issues


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.