2
votes

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));
1
why this? $this->content[] ,why not $this->contentmpm
@mpm because that is in a while loop so it iterates multiple timesZach Starnes
dump(value) and see how it lookskskaradzinski
where do you render the template?mpm

1 Answers

0
votes

So the issue was not the loop. It was working fine.

The issue was I was not passing the content in the right way, I just was not paying attention. Silly mistake.

I had this: $template->display($content);

and it needed to be this $template->display(array('content' => $content));