|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
flank Smarty n00b
Joined: 11 Dec 2013 Posts: 1
|
Posted: Wed Dec 11, 2013 2:41 pm Post subject: Trouble in loop foreach |
|
|
Hi! I'm new at the forum.
I'm working with prestashop, and I'm having trouble resolving this.
This is my php file:
Code: | $sqlc[] = array();
$sqlct[] = array();
$i= 0;
if ($resultscat = Db::getInstance()->ExecuteS($sqlcat)) {
foreach ($resultscat as $categorias) {
$cat[$i] = $categorias['nombre'];
$sqlc[$i] = 'SELECT * FROM `'._DB_PREFIX_.'destinos` WHERE categoria = "'. $cat[$i] .'"' ;
$this->context->smarty->assign($cat[$i] , Db::getInstance()->ExecuteS($sqlc[$i]));
$i++;
}
} |
So far everything is good.
The trouble is in my .tpl file:
Code: | {foreach from=$query_cat item=categoria}
{$categoria.nombre}
{foreach from=$categoria.nombre item=destinos}
<article id="destino_{$destinos.id_destinos}" class="destino-box {$destinos.categoria}" data-category='{$destinos.categoria}' >
<img src="{$imgDir}{$destinos.image}" width="211" height="117" />
<h1 class="title">{$destinos.title}</h1>
<p>{$destinos.scaption|truncate:"200":"..."} <a href="{$base_uri}destinos/{$destinos.id_destinos}-{$destinos.link_rewrite}" class="view-more">+info</a></p>
</article>
{/foreach}
{/foreach} |
The error is:
The smarty don't find the var "from" in the foreach.
Is there any way to fix this?
Thank you |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Dec 11, 2013 7:45 pm Post subject: |
|
|
I think you missed to assign a value for $query_cat.
Code: |
$sqlc[] = array();
$sqlct[] = array();
$i= 0;
if ($resultscat = Db::getInstance()->ExecuteS($sqlcat)) {
-> $this->context->smarty->assign('query_cat',$resultscat);
foreach ($resultscat as $categorias) {
$cat[$i] = $categorias['nombre'];
$sqlc[$i] = 'SELECT * FROM `'._DB_PREFIX_.'destinos` WHERE categoria = "'. $cat[$i] .'"' ;
$this->context->smarty->assign($cat[$i] , Db::getInstance()->ExecuteS($sqlc[$i]));
$i++;
}
}
|
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|