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

Help to Convert PHP to Smarty

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
AlbertoALH
Smarty n00b


Joined: 11 Sep 2016
Posts: 1

PostPosted: Sun Sep 11, 2016 4:14 am    Post subject: Help to Convert PHP to Smarty Reply with quote

Hi, i using smarty, how to convert this part of code PHP to smarty engine...

HOW TO FOREACH IN SMARTY??????

TANK'S!!

Quote:
<table class="tbl-qa">
<thead>
<tr>
<th class="table-header" width="10%">Q.No.</th>
<th class="table-header">Question</th>
<th class="table-header">Answer</th>
</tr>
</thead>
<tbody>
<?php
foreach($faq as $k=>$v) {
$pergunta = $faq[$k]["pergunta"];
$resposta = $faq[$k]["resposta"];

?>
<tr class="table-row">
<td><?php echo $k+1; ?></td>
<td contenteditable="true" onBlur="saveToDatabase(this,'pergunta','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $pergunta; ?></td>
<td contenteditable="true" onBlur="saveToDatabase(this,'resposta','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $resposta; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Sun Sep 11, 2016 5:05 pm    Post subject: Reply with quote

Smarty3 has a similar syntax like PHP.

You have only to assign $faq to Smarty

http://www.smarty.net/docs/en/api.assign.tpl

And then you can transform your snippet into Smarty template

http://www.smarty.net/docs/en/language.function.foreach.tpl

and display it

http://www.smarty.net/docs/en/api.display.tpl
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1568

PostPosted: Sun Sep 11, 2016 8:51 pm    Post subject: Reply with quote

First you should stop using foreach() like that, though.
And before that, stop yelling at people for no reason.

Code:
{foreach $faq as $v}<tr class="table-row">
 <td>{$v@key+1}</td>
 <td contenteditable="true" onBlur="saveToDatabase(this,'pergunta','{$v.id}')" onClick="showEdit(this);">{$v.pergunta}</td>
 <td contenteditable="true" onBlur="saveToDatabase(this,'resposta','{$v.id}')" onClick="showEdit(this);">{$v.resposta}</td>
 </tr>{/foreach}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development 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