Uncaught Twig\Error\SyntaxError: A hash key must be followed by a colon (:)
Uncaught Twig\Error\SyntaxError: A hash key must be followed by a colon (:)
我想知道是否可以就我的语法错误获得一些帮助,因为我对 Twig 还很陌生。
这是我的数组:
{% set bookings = {
"Tuesday": {
"1315", // this line is causing the error
"1330",
"1345",
"1430",
"1445",
"1460",
"1515",
"1530",
"1545",
"1630",
"1715",
"1730",
"1745",
"1815",
"1830",
"1845"
},
"Wednesday" : {
"0930",
"0945",
"1015",
"1030",
"1045",
"1115",
"1130",
"1215",
"1230",
"1245",
"1415",
"1445",
"1530",
"1630",
"1645",
"1815",
"1830"
},
"Thursday": {
"0900",
"0915",
"0930",
"0945",
"1000",
"1015",
"1030",
"1045",
"1100",
"1115",
"1130",
"1145",
"1200",
"1215",
"1230",
"1245",
"1300",
"1315",
"1330",
"1345",
"1400",
"1415",
"1430",
"1445",
"1500",
"1515",
"1530",
"1545",
"1715",
"1730",
"1745"
},
"Friday" : {
"1015",
"1030",
"1045",
"1215",
"1230",
"1245",
"1430",
"1445"
}
} %}
我收到的错误消息是:
PHP Fatal error: Uncaught Twig\Error\SyntaxError: A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "," ("punctuation" expected with value ":").
我确信它相当简单,但我在他们的文档中似乎找不到 - 我得到的最接近的是一个描述 how to set variables 的页面,但它不是深度。
谢谢。
Twig hashes,包裹着 { }
,是从键到值的映射。由于您的嵌套结构只是一个值列表,因此您应该使用数组,用 [ ]
:
包裹
{% set bookings = {
"Tuesday": [
"1315",
"1330",
...
],
"Wednesday": [
"0930",
...
],
...
} %}
我想知道是否可以就我的语法错误获得一些帮助,因为我对 Twig 还很陌生。
这是我的数组:
{% set bookings = {
"Tuesday": {
"1315", // this line is causing the error
"1330",
"1345",
"1430",
"1445",
"1460",
"1515",
"1530",
"1545",
"1630",
"1715",
"1730",
"1745",
"1815",
"1830",
"1845"
},
"Wednesday" : {
"0930",
"0945",
"1015",
"1030",
"1045",
"1115",
"1130",
"1215",
"1230",
"1245",
"1415",
"1445",
"1530",
"1630",
"1645",
"1815",
"1830"
},
"Thursday": {
"0900",
"0915",
"0930",
"0945",
"1000",
"1015",
"1030",
"1045",
"1100",
"1115",
"1130",
"1145",
"1200",
"1215",
"1230",
"1245",
"1300",
"1315",
"1330",
"1345",
"1400",
"1415",
"1430",
"1445",
"1500",
"1515",
"1530",
"1545",
"1715",
"1730",
"1745"
},
"Friday" : {
"1015",
"1030",
"1045",
"1215",
"1230",
"1245",
"1430",
"1445"
}
} %}
我收到的错误消息是:
PHP Fatal error: Uncaught Twig\Error\SyntaxError: A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "," ("punctuation" expected with value ":").
我确信它相当简单,但我在他们的文档中似乎找不到 - 我得到的最接近的是一个描述 how to set variables 的页面,但它不是深度。
谢谢。
Twig hashes,包裹着 { }
,是从键到值的映射。由于您的嵌套结构只是一个值列表,因此您应该使用数组,用 [ ]
:
{% set bookings = {
"Tuesday": [
"1315",
"1330",
...
],
"Wednesday": [
"0930",
...
],
...
} %}