나는 주위를 둘러 보았습니다. TWIG의 제작자는 실제로 내가보기에 순수한 직업 인 템플릿을 사용해야한다고 주장합니다. 전혀 돌 보지 않니?!TWIG에서 stdClass의 속성에 액세스 할 수 없습니다.
몇 가지 맞춤 TWIg 필터없이 stdClass 객체를 반복 할 수 없다는 것을 알고 있으므로 지금 해킹했습니다.하지만 동적으로 속성에 액세스 할 수없는 경우이 TWIG는 실제로 전혀 유용하지 않습니다. . 여기
$fixedModuleNames = array('time', 'date', 'weather'); //since TWIG doesn't iterate over objects by default, this is my solution, don't feel like adding a bunch of twigfilters just for this.
$fixedModules = json_decode($entity->getFixedModules());
/*
Here's what fixedModules look like (although here not JSON but array, before encoded to json, I like to create my JSONs this way in PHP)
$fixedModules["time"] = array(
'show' => true,
'left' => 10,
'top' => 10,
'width' => 100,
'height' => 200,
'fontColor' => '#000000',
'fontSize' => 40,
'fontFamily' => 'Arial',
'borderColor' => '',
'borderRounding'=> 0,
'bgColor' => ''
);
*/
내가 할 노력하고 있어요 ...
{% for item in fixedModuleNames %}
<TR>
<TD><input type="number" id="left_{{ item }}" value="{{ fixedModules[item].left }}" class="LayoutModuleEditField" /></TD>
그래서이 줄
{{ fixedModules[item].left }}
매우 일상이다 내가 무엇을하고 있는가 때문에이 주위에 방법이 있어야합니다 실패 무엇 ?
레코드의 경우 :'json_decode'의 두 번째 매개 변수로'true'를 전달하면'\ stdClass' 인스턴스 대신에 연관 배열이됩니다. – Maerlyn
니스! 그럼에도 불구하고 각 섹션의 "이름"을 잃어 버리는 것 같습니다 (위의 예에서 "시간"). 그걸 보존 할 방법이 있을까요? –