Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to Loop a Template?

    Hi,
    I have a template that has mostly HTML and some data from php in form of <?=$text;?>. I have a page that need to have the content with same format (the format in the template) with different data. How can I loop the template couple time in the web page? I try to reuse the template, not create a string of the content of the same template and then echo them.

    Many thanks.

  • #2
    New Coder
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't quite understand. You mean like your template with all the content, and then it again underneath it without? A picture may help me.

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Usually you would have your template split into include files.
    Header, menu, footer etc.

    If you have them in variables then you could do something similar to

    PHP Code:
    <?php
    $head 
    '<table width="80%"  border="1" align="center" cellpadding="2" cellspacing="0"><tr><td>';
    $foot '</td></tr></table><br>';
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>
    <table width="80%"  border="1" align="center" cellpadding="2" cellspacing="0">
      <tr>
        <td><br>
        <?php
        
    for($x=0$x<5$x++){
            echo 
    $head;
            echo 
    'This is box number ' $x;
            echo 
    $foot;
        }
        
    ?>
        </td>
      </tr>
    </table>
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •