|
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 |
Yoda Smarty n00b
Joined: 10 Jun 2021 Posts: 1
|
Posted: Thu Jun 10, 2021 6:26 pm Post subject: Something I don't understand with assigning values |
|
|
Hello
I'm trying to develop a plugin for the piwigo gallery system. Piwigo is using smarty templates, so that's why I'm here
My issue (but probably just something I don't understand (I'm not a real developper, but I have some self pratice knowledge)
Current situation : I have to create a list of input fields (1 text field and 1 checkbox).
I tough that the best way to do this is in a table.
I tried this for testing :
Code: | <form method="post" action="{$PLUGINPCCO_F_ACTION}" class="general">
<table>
<tr>
<th>Utilisateur Wordpress</th><th>Autologin actif</th>
</tr>
<tr>
<td><input type="text" label="L1" name="WPL1" value="{$PLUGINPCCO_WPL1}" /></td>
<td align="center"><input type="checkbox" label="A1" name="ACT1" value="{$PLUGINPCCO_ACT1}" /></td>
</tr>
<tr>
<td><input type="text" label="L2" name="WPL2" value="{$PLUGINPCCO_WPL2}" /></td>
<td align="center"><input type="checkbox" label="A2" name="ACT2" value="{$PLUGINPCCO_ACT2}" /></td>
</tr>
</table>
<p><input type="submit" value="Enregistrer" name="submit" /></p>
</form> |
filled by php using
Code: | $template->assign('PLUGINPCCO_WPL1', $me->my_config['WPL1']);
if ($me->my_config['ACT1'] == 1){
$template->assign('PLUGINPCCO_ACT1', 'checked');
}else {
$template->assign('PLUGINPCCO_ACT1, 'unchecked');
};
$template->assign('PLUGINPCCO_WPL2', $me->my_config['WPL2']);
if ($me->my_config['ACT2'] == 1){
$template->assign('PLUGINPCCO_ACT2', 'checked');
}else {
$template->assign('PLUGINPCCO_ACT2, 'unchecked');
}; |
And it was OK and displayed at the right place in the plugin configuration
But, the number of tables lines needs to be variable. So I decided to replace the two lines test table by a variable.
{$PLUGINPCCO_PHP_TABLE}
And I fill the variable in php by
Code: |
$columns = array_keys($columns);
$user_table = '<table><thead><tr>';
$user_table = $user_table . '<th>Utilisateur</th><th>Autologin actif</th>';
$user_table = $user_table . '</tr></thead><tbody>';
$i=1;
foreach($rows as $row) {
$user_table = $user_table . '<tr>';
$user_table = $user_table . '<td><input type="text" label="L'.$i.'" name="WPL'.$i.'" value="'.$row[$columns[0]].'" /></td>';
if ($row[$columns[1]] == 1){
$user_table = $user_table . '<td align="center"><input type="checkbox" label="A'.$i.'" name="ACT'.$i.'" value="1" checked /></td>';
}else {
$user_table = $user_table . '<td align="center"><input type="checkbox" label="A'.$i.'" name="ACT'.$i.'" value="1" unchecked /></td>';
};
$user_table = $user_table . '</tr>';
$i++;
}
$user_table = $user_table . '</tbody></table>';
$template->assign('{$PLUGINPCCO_PHP_TABLE}', $me->$user_table);
|
Fields are well filled and displayed. But, not at the right place !the "table variable" is not displayed at the same coordinates than the "static table". It's displayed in the header of the page...
Just to explain : If I keep both of them, like this
Code: |
<form method="post" action="{$PLUGINPCCO_F_ACTION}" class="general">
{$PLUGINPCCO_PHP_TABLE}
<table>
<tr>
<th>Utilisateur Wordpress</th><th>Autologin actif</th>
</tr>
<tr>
<td><input type="text" label="L1" name="WPL1" value="{$PLUGINPCCO_WPL1}" /></td>
<td align="center"><input type="checkbox" label="A1" name="ACT1" value="{$PLUGINPCCO_ACT1}" /></td>
</tr>
<tr>
<td><input type="text" label="L2" name="WPL2" value="{$PLUGINPCCO_WPL2}" /></td>
<td align="center"><input type="checkbox" label="A2" name="ACT2" value="{$PLUGINPCCO_ACT2}" /></td>
</tr>
</table>
<p><input type="submit" value="Enregistrer" name="submit" /></p>
</form>
|
The result is this one : The static table is displayed à the right place, the "variable" table is displayed in the header of the page !
I spend hours to check why.
I'm lost, I don't understand why static or variable, at the same place in the template, are not displayed at the same place in the page.
Any advice is welcome
Thanks in advance. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Jun 13, 2021 3:01 am Post subject: |
|
|
Why you are creating table in PHP?
Do that in Smarty. |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Tue Jun 15, 2021 9:55 pm Post subject: |
|
|
Let me make this first reply:
Don't do this:
$template->assign('{$PLUGINPCCO_PHP_TABLE}', $me->$user_table);
Do this:
$template->assign('PLUGINPCCO_PHP_TABLE', $user_table); |
|
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
|