Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

dynamic table in smarty template

 
Post new topic   Reply to topic    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
egokyniker
Smarty Rookie


Joined: 24 Oct 2015
Posts: 9

PostPosted: Fri Aug 18, 2017 11:59 am    Post subject: dynamic table in smarty template Reply with quote

hello,
i try to write a dynamic table but do not know what is wrong?
can someone help me?
Code:

{/literal}
   $iQuantity = (integer)$_POST['klausur_aufgaben'];
   $aTableHeads = [];
   $aTableContents = [];
   
{for $x=0 to $iQuantity;}
 //  {for( $x=0; $x<$iQuantity; $x++ )

$aTableHeads[] = '<th>' . ($x + 1) . '</th>';
$aTableContents[] = '<td><input type="text" id="punkte' . (string)$x . '" name="punkte' . (string)$x . '" value="{$punkte.' . (string)$x . '}" size="3" onKeyUp="aktualisieren('punkte. (string)$x . '",'punkte. (string)$x+1 . '"></td>';
    {/for}
{literal}


Last edited by egokyniker on Fri Aug 18, 2017 1:59 pm; edited 1 time in total
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1147

PostPosted: Fri Aug 18, 2017 1:08 pm    Post subject: Reply with quote

Why do you mix presentation logic with business logic?
Back to top
View user's profile Send private message
egokyniker
Smarty Rookie


Joined: 24 Oct 2015
Posts: 9

PostPosted: Fri Aug 18, 2017 1:59 pm    Post subject: Reply with quote

AnrDaemon wrote:
Why do you mix presentation logic with business logic?

so better?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1147

PostPosted: Fri Aug 18, 2017 8:17 pm    Post subject: Reply with quote

You should know your table structure ( = the data that fills it) before you pass control to Smarty.
I hardly understand what you are doing, without seeing some sample source data.
Back to top
View user's profile Send private message
egokyniker
Smarty Rookie


Joined: 24 Oct 2015
Posts: 9

PostPosted: Fri Aug 18, 2017 9:09 pm    Post subject: Reply with quote

sorry, i will explain it:
i want a dynamic table, and the number of columns depends on the value 'klausuraufgaben', so after user post a number[3-8] for 'klausuraufgaben', the code should generate a table with corresponding columns, and the user is able to fill the columns with points.
Example: user post 3, table has 3 columns.
on the following way with if it functioned, but it is too much code:

Code:

<!-- Anzahl der Aufgaben 3-->
  {if $klausuraufgaben == 3}
   <table cellpadding="3" cellspacing="0" border="1">
   <tr>
        <th>Aufgabe</th>
        <th>1</th>
        <th>2</th>
        <th>3</th>
        <th>Summe</th>
        <th>Note</th>
     </tr>
     <tr>
     <td> </td>      
      <td><input type="text" id="punkte0" name="punkte0" value="{$punkte.0}" size="3" onKeyUp="aktualisieren('punkte0','punkte1')" /></td>
      <td><input type="text" id="punkte1" name="punkte1" value="{$punkte.1}" size="3" onKeyUp="aktualisieren('punkte1','punkte2')" /></td>
      <td><input type="text" id="punkte2" name="punkte2" value="{$punkte.2}" size="3" onKeyUp="aktualisieren('punkte2','punkte3')" /></td>
      <td id="tds1">0</td>
      <td></td>
     </tr>
     <tr>
       <td>Gesamt</td>
       <td colspan="3"></td>
       <td id="summe">0</td>
      <td id="note">{$student.note/10}</td>
    </tr>
  </table>
  {/if}
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1147

PostPosted: Sat Aug 19, 2017 3:51 pm    Post subject: Reply with quote

There's nothing "dynamic" in Smarty output, ever.
All its output is by definition static.
What you are trying to achieve is best done using client scripting.
Back to top
View user's profile Send private message
bsmither
Smarty Pro


Joined: 20 Dec 2011
Posts: 134
Location: West Coast

PostPosted: Sat Aug 19, 2017 4:12 pm    Post subject: Reply with quote

Is it possible that Smarty's custom function HTML Table be a solution?
https://www.smarty.net/docs/en/language.function.html.table.tpl
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Language: German 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