Answer the question
In order to leave comments, you need to log in
Why is the loop not output in twig?
hello here is the php code
$posts = mysql_query("SELECT * FROM ".$db_prefix."posts");
$posts = mysql_fetch_array($posts);
foreach($posts as $key => $value){
$name_post = $posts["name"];
$mini_desc = $posts["mini_desc"];
$view = $posts["view"];
$date = $posts["date"];
$min_img = $posts["img"];
}
{% extends "main.html" %}
{% block content %}
{% for posts in key %}
<div id="content">
<div class="post-item ">
<h2><a href="blog/">{{ name_post }}</a></h2>
<div class="img-conteiner">
<img src="/images/icons/708.jpg" />
</div>
<p>{{ mini_desc}}</p>
<div class="clear"></div>
<div class="post-info">
<span class="date_add">{{ date }}</span>
<span style="background: #0ba0dd;" class="post-rub"><a href="blog/moi-sobyitiya.html">{{ cat }}</a></span>
<span class="views">Просмотров: {{ view }}</span>
</div>
{% endfor %}
{% endblock %}
Answer the question
In order to leave comments, you need to log in
{% for post in posts %}
{{ post.name %}
{{ post.img }}
{% endfor %}
In the name of Satan, of course!
I think you should still read the twig documentation. I have no idea why you need this foreach where you send data. I also don't understand why you have posts in key in the loop even though it should be post in posts. And I don't understand why mysql_* and not mysqli/PDO. Stop using obsolete extensions.
$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);
$twig->render('template.twig', compact('posts'));
{% for post in posts %}
{{ post.name }}
{% endfor %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question