|
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 |
egokyniker Smarty Rookie
Joined: 24 Oct 2015 Posts: 10
|
Posted: Fri Aug 18, 2017 11:59 am Post subject: dynamic table in smarty template |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Aug 18, 2017 1:08 pm Post subject: |
|
|
Why do you mix presentation logic with business logic? |
|
Back to top |
|
egokyniker Smarty Rookie
Joined: 24 Oct 2015 Posts: 10
|
Posted: Fri Aug 18, 2017 1:59 pm Post subject: |
|
|
AnrDaemon wrote: | Why do you mix presentation logic with business logic? |
so better? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Aug 18, 2017 8:17 pm Post subject: |
|
|
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 |
|
egokyniker Smarty Rookie
Joined: 24 Oct 2015 Posts: 10
|
Posted: Fri Aug 18, 2017 9:09 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Aug 19, 2017 3:51 pm Post subject: |
|
|
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 |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
|
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
|