|
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 |
Crazy- Smarty Rookie
Joined: 12 Oct 2003 Posts: 5
|
Posted: Sun Oct 12, 2003 1:28 pm Post subject: Nested Section |
|
|
I'm busy with a howto section on my site with Cats and sub-cats
but now i don't get the subcats under de cats:
[php:1:f9f6ce128d]$DB->uitvoeren("SELECT * FROM howtos_cats");
while($howtos_cats_array = $DB->uitlezen()) {
$cats[] = array(
'cat_naam' => $howtos_cats_array['cat_naam'],
'cat_pic' => "/images/howtos/".$howtos_cats_array['pic'],
);
// haal de subcats eruit
$DB2->uitvoeren("SELECT * FROM howtos_sub_cats WHERE cat_id = $howtos_cats_array[id]");
while($howtos_subcats_array = $DB2->uitlezen()) {
$sub_cats[] = array(
'sub_naam' => $howtos_subcats_array['sub_naam'],
);
}
}
// maak het klaar voor de template
$so->assign("cats",$cats);
$so->assign("sub_cats",$sub_cats);[/php:1:f9f6ce128d]
and the template
Code: | {section name=cat loop=$cats start=1}
{$cats[cat].cat_naam}
{section name=subcat loop=$sub_cats[cat]}
{$sub_cats[cat][subcat].sub_naam}
{/section}
{/section} |
could somebody help me? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Oct 12, 2003 2:23 pm Post subject: |
|
|
{section} is for indexed arrays. You want {foreach} which works with associative arrays. |
|
Back to top |
|
Crazy- Smarty Rookie
Joined: 12 Oct 2003 Posts: 5
|
Posted: Sun Oct 12, 2003 3:26 pm Post subject: |
|
|
can you explain it a little bit ? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Oct 12, 2003 4:10 pm Post subject: |
|
|
I think my reply was hasty
it looks like your subcats is not 2 dimensional. perhaps something like this
$sub_cats[$i][] = array( 'sub_naam' => $howtos_subcats_array['sub_naam']);
and $i starts at 0 and is incremented for each new cat |
|
Back to top |
|
Crazy- Smarty Rookie
Joined: 12 Oct 2003 Posts: 5
|
Posted: Sun Oct 12, 2003 4:23 pm Post subject: |
|
|
stupid me !
you're right
thnx a lot |
|
Back to top |
|
Crazy- Smarty Rookie
Joined: 12 Oct 2003 Posts: 5
|
Posted: Mon Oct 13, 2003 11:36 am Post subject: |
|
|
hm, when i put a howto under a subcat, the ID is +1
so:
howto: subcat_id = 1
then it is showed under sucat_id 2 !
Code: | {section name=cat loop=$cats start=1}
{$cats[cat].cat_naam}
{section name=subcat loop=$sub_cats[cat]}
{$sub_cats[cat][subcat].sub_naam}
{section name=howtos loop=$howtos[cat][subcat]}
{$howtos[cat][subcat][howtos].howto_titel}
{/section}
{/section}
{/section} |
|
|
Back to top |
|
Crazy- Smarty Rookie
Joined: 12 Oct 2003 Posts: 5
|
Posted: Tue Oct 14, 2003 8:19 am Post subject: |
|
|
somebody? |
|
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
|