|
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 |
Aar Smarty Rookie
Joined: 19 Jul 2011 Posts: 12
|
Posted: Wed May 31, 2017 8:23 am Post subject: Create categories in a Smarty loop |
|
|
Hello,
I have a question,
How can I group the numbers by category, in Smarty?
Each item has a field 'categorie' with his categorie.
How can i group them in Smarty?
On this way:
Quote: |
-Train A
2101
2102
-Train B
2103
- Train C
2104
|
I have this array:
Code: |
Smarty_Variable Object (3)
->value = Array (9)
0 => Array (8)
afkorting => "SM90"
naam => "RailHopper (SM'90)"
nummer => "2101"
opmerkingen => ""
aflevering => "0000-00-00"
indienststelling => "0000-00-00"
gesloopt => "2007-02-15"
status => "Gesloopt"
categorie => "Train A"
1 => Array (8)
afkorting => "SM90"
naam => "RailHopper (SM'90)"
nummer => "2102"
opmerkingen => ""
aflevering => "0000-00-00"
indienststelling => "0000-00-00"
gesloopt => "0000-00-00"
status => "Gesloopt"
categorie => "Train A"
2 => Array (8)
afkorting => "SM90"
naam => "RailHopper (SM'90)"
nummer => "2103"
opmerkingen => ""
aflevering => "0000-00-00"
indienststelling => "0000-00-00"
gesloopt => "0000-00-00"
status => "Gesloopt"
categorie => "Train B"
3 => Array (8)
afkorting => "SM90"
naam => "RailHopper (SM'90)"
nummer => "2104"
opmerkingen => ""
aflevering => "0000-00-00"
indienststelling => "0000-00-00"
gesloopt => "2007-02-16"
status => "Gesloopt"
categorie => "Train C"
->nocache = false
->scope = "Smarty root"
|
And this code:
Code: |
{section name=nummers loop=$nummer_list}
<tr>
<td width="15%"><a href="/spots/{$nummer_list[nummers].nummer}">{$nummer_list[nummers].nummer}</a></td>
<td width="20%">{if $nummer_list[nummers].aflevering =="0000-00-00"} - {else} {$nummer_list[nummers].aflevering|date_format:"%e %b %Y"}{/if}</td>
<td width="20%">{if $nummer_list[nummers].indienststelling =="0000-00-00"} - {else} {$nummer_list[nummers].indienststelling|date_format:"%e %b %Y"}{/if}</td>
<td width="20%">{if $nummer_list[nummers].gesloopt=="0000-00-00"}- {else} {$nummer_list[nummers].gesloopt|date_format:"%e %b %Y"}{/if}</td>
<td width="20%">{$nummer_list[nummers].status}</td>
<td width="5%">{if $nummer_list[nummers].opmerkingen}<img src="img/add.png" alt="Uitklappen" class="opmtoggle" />{/if}</td>
</tr>
{/section} |
Anyone an idea, how i could do this? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed May 31, 2017 3:31 pm Post subject: |
|
|
Group them in your PHP code.
And pass to Smarty only what it should render. |
|
Back to top |
|
Aar Smarty Rookie
Joined: 19 Jul 2011 Posts: 12
|
Posted: Wed May 31, 2017 3:38 pm Post subject: |
|
|
And how can i group the list by the categories in Smarty?
That's my question....
Any idea, how i can solve this? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed May 31, 2017 8:12 pm Post subject: |
|
|
Smarty is a templating engine, not a programming language. |
|
Back to top |
|
Aar Smarty Rookie
Joined: 19 Jul 2011 Posts: 12
|
Posted: Wed May 31, 2017 8:28 pm Post subject: |
|
|
AnrDaemon wrote: | Smarty is a templating engine, not a programming language. |
I know, but HOW can i solve this?
In my eyes, this is a logical operation. Not a programming operation.
In PHP it is:
Code: |
<?php
$result = mysqli_query($conn, $sql);
$previousItem = '';
while($data = mysqli_fetch_assoc($result))
{
if( $previousItem != $data['categorie'] )
{
echo '<h1>'.$data['categorie'] ).'</h1>';
$previousItem = $data['categorie'];
}
echo '<tr>
<td>Nummer: '.$data['nummer'].'</td>
</tr>';
}
?>
|
But how in/with Smarty?
Maybe you can more helpful? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed May 31, 2017 9:29 pm Post subject: |
|
|
Again, this is not a Smarty question.
It should not be solved with Smarty. |
|
Back to top |
|
Aar Smarty Rookie
Joined: 19 Jul 2011 Posts: 12
|
Posted: Wed May 31, 2017 9:31 pm Post subject: |
|
|
Again...
How can i solve this with Smarty and PHP?
Sorry, but why your steadfastness? I do not want to get angry, but why do I have to ask my question three times?
It could not have been harmful to give a good solution. |
|
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
|