Jump to content

How to use Smarty ?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
kid304

kid304

    Newbie

  • Members
  • PipPip
  • 14 posts
I wanna show my data into a table like this:

Quote

<table>
<?
$count=0;
while( not until the last record) {
if ( $count==0 )
{
echo "<tr> <td>" ;
echo "Data"
$count++;
}
else {
echo "<td>"
echo "Data"
$count++;

}

if ( $count==4 ) {
echo "</td></tr>";
$count=0;
}
else echo "</td>"
}
?>
</table>

This will show 4 records in each rows of table. (if $count = 4, I will create new row )
But I want to use Smarty to do that...? Is it possible?

Edited by kid304, 04 December 2009 - 06:13 AM.


#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
in your smarty template, do an foreach or section loop

<table><tr>
{foreach from=$myvar item=i name=myloop}
<td>{$i}</td>
{if $smarty.foreach.myloop.index % 4 == 3}</tr><tr>{/if}
{/foreach}
</tr></table>

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
kid304

kid304

    Newbie

  • Members
  • PipPip
  • 14 posts
Thanks so much !....
Smarty is so smart...:D

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
I think so too, have you read my Smarty tutorials here on Codecall?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#5
kid304

kid304

    Newbie

  • Members
  • PipPip
  • 14 posts
I begin to learn Smarty, I believe that always exist solutions for my requirements...:)
Hope tutorials here will help me.

#6
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
Here's the tutorial series I'm talking about.
http://forum.codecal...tion-setup.html
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#7
kid304

kid304

    Newbie

  • Members
  • PipPip
  • 14 posts
Thank you !
That's really good post. Smarty have too many functions for us to use.
It's so convenient.
Maybe Part 4 coming up ? :)

#8
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
It will, when I take my time to write it.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall