Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Create categories in a Smarty loop

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Aar
Smarty Rookie


Joined: 19 Jul 2011
Posts: 12

PostPosted: Wed May 31, 2017 8:23 am    Post subject: Create categories in a Smarty loop Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed May 31, 2017 3:31 pm    Post subject: Reply with quote

Group them in your PHP code.
And pass to Smarty only what it should render.
Back to top
View user's profile Send private message
Aar
Smarty Rookie


Joined: 19 Jul 2011
Posts: 12

PostPosted: Wed May 31, 2017 3:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed May 31, 2017 8:12 pm    Post subject: Reply with quote

Smarty is a templating engine, not a programming language.
Back to top
View user's profile Send private message
Aar
Smarty Rookie


Joined: 19 Jul 2011
Posts: 12

PostPosted: Wed May 31, 2017 8:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed May 31, 2017 9:29 pm    Post subject: Reply with quote

Again, this is not a Smarty question.
It should not be solved with Smarty.
Back to top
View user's profile Send private message
Aar
Smarty Rookie


Joined: 19 Jul 2011
Posts: 12

PostPosted: Wed May 31, 2017 9:31 pm    Post subject: Reply with quote

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. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP