Talesoft / tale-jade

A complete and fully-functional implementation of the Jade template language for PHP
http://jade.talesoft.codes
MIT License
88 stars 10 forks source link

Multidimensional array issue #119

Closed brocococonut closed 8 years ago

brocococonut commented 8 years ago

JSON based array of objects doesn't work. Placing each of the objects in quotation marks helps.. but doesn't help when it comes to iterating over the objects as well.

$arrayVar = [{'id':'1','catName':'Candles'},{'id':'2','catName':'Greeting Cards'},{'id':'4','catName':'Bath Bombs'},{'id':'6','catName':'Category Name'},{'id':'7','catName':'Category Test'}]

ul
  each $item in $arrayVar
    li= $item

Something similar would be easier to perform in vanilla jade, but I'm not entirely sure of the syntax here on tale-jade. I'd like to be able to do the following:

$arrayVar = [{'id':'1','catName':'Candles'},{'id':'2','catName':'Greeting Cards'},{'id':'4','catName':'Bath Bombs'},{'id':'6','catName':'Category Name'},{'id':'7','catName':'Category Test'}]

select#slectID
  each $item in $arrayVar
    option(value= $item.id)= $item.catName
YamiOdymel commented 8 years ago

Just a notice that tale-jade is not a Jade for PHP (If you don't know it),

and tale-jade use original PHP syntax usually, not sure how to explain it,

but tale-jade like to make the variables stay originally instead of compile (or modifiy?) them,

in your first example, you can only do this with

$arrayVar = [['id' => 1, 'catName' => 'Candles'], ['id' => '2', 'catName' => 'Greeting Cards'], ['id':'4','catName':'Bath Bombs'], ['id' => '6', 'catName' => 'Category Name'], ['id' => '7', 'catName' => 'Category Test']]

and the each loop

In Jade

select#slectID
  each $item in $arrayVar
    option(value= $item.id)= $item.catName

In Tale-Jade

select#slectID
  each $item in $arrayVar
    option(value= $item['id'])= $item['catName']
brocococonut commented 8 years ago

Ahh right~ The main issue I was apparently having was the formatting of arrays. I figured it was more like Jade, so I was converting an already multidimensional php array into JSON. Seeing as it prefers PHP style variables and arrays, I was able to just pass in the array and use it directly without any conversion.