I have created this mulidimentional array in a php model. which is below.
$handle = opendir($this->path);
while(false !== ($file = readdir($handle)))
{
if($file != "." && $file != "..")
{
$this->content[] = array(
'name' => $file,
'name_href' => $file,
'extn' => $this->findExts($file),
'file_size' => number_format(filesize($this->path . '/' . $file)),
'mod_time' => date("M j Y g:i A", filemtime($this->path . '/' . $file)),
'time_keys' => date("YmdHis", filemtime($this->path . '/' . $file))
);
}
}
closedir($handle);
and I am trying to loop through it with twig. But the page does not show any content. However if I print_r
the $content
array all the data shows up so I know the array is not empty. Can someone help me find out how I can loop through this and display the content.
here is what I have tried
{% for key, value in content %}
<li>
<a class="show_content" href="{{ value.name_href }}">{{ value.name }}</a>
</li>
{% endfor %}
but this does not display anything. And here is where I pass the content into the twig template.
$template = $twig->loadTemplate('layout.html.twig');
$template->display(array('content' => $content));
dump(value)
and see how it looks – kskaradzinski