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 2 of 2
  1. #1
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    924
    Thanks
    76
    Thanked 29 Times in 29 Posts

    Starting a template.

    Hi, I have watched a few videos on making a template and watched one from Lynda.com.

    I want to produce a template designed site. I'm having trouble deciding the filenames and I am not sure if I have to create multiple files containing hardcoded html or whether I can have one file which is searched and depending on code in there will return the specific html to be outputted.

    Here is what I have:

    This is called index.php at the moment and contains this code:
    PHP Code:
    <?php

    $link 
    = (isset($_GET['title'])) ? mysql_real_escape_string($_GET['title']) : 'home';

    $link ucfirst($link);

    switch (
    $link) {

       case 
    'Home':  
          
    $file file_get_contents("homepage.php");
          
    $file preg_replace("/{title}/","Gardenable - {$link}",$file);
       break;
       default:
          
    $file file_get_contents("homepage.php");
          
    $file preg_replace("/{title}/","Gardenable - {$link}",$file);
    }

    echo 
    $file;
    ?>
    And this is my homepage.php, which contains just plain html:
    PHP Code:
    <html>
    <
    head>
    <
    title>{title}</title>
    <
    link rel="stylesheet" type="text/css" href="css/style.css" />
    </
    head>

    <
    body>
    <
    div id="container">

       <
    div id="header">
          <
    img src="images/logo1.jpg" alt="Gardenable Logo" title="Gardenable" id="logo" border="0" />
          
          <
    div id="slogan_div">
              <
    h2>Making gardening accessible to everyone!</h2>
          </
    div>
          
          <
    div id="menu_div">
             <
    ul>
                <
    li><a href='index.php?title=home'>Home<a/></li>|
                <
    li><a href='index.php?title=about'>About Us</a></li>|
                <
    li><a href='index.php?title=gallery'>Gallery</a></li>|
                <
    li><a href='index.php?title=contact'>Contact</a></li>
             </
    ul>
          </
    div>
       </
    div>

    </
    div>
    </
    body>
    </
    html
    I'm having difficulty visioning how I will create the other pages and use the index.php to echo the contents. It seems if I have to create different files containing html for the different pages, then echo'ing it out depending on results, then it would not come across as a template. I wanted to create a template which just loads content to a page which already has a design layout. For instance, I have one main div which is for ALL content for that certain page, how can I dynamically load content into it depending on if the user changes the page.

    Regards,

    Lc.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,338
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Easy really..

    Code:
    <html>
    <head>
    <title>{title}</title>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    </head>
    
    <body>
    {content}
    </body>
    </html>
    In your homepage php code you load this via file_get_contents() and merge it with your template like you would the title:
    Code:
    <div id="container">
    
       <div id="header">
          <img src="images/logo1.jpg" alt="Gardenable Logo" title="Gardenable" id="logo" border="0" />
          
          <div id="slogan_div">
              <h2>Making gardening accessible to everyone!</h2>
          </div>
          
          <div id="menu_div">
             <ul>
                <li><a href='index.php?title=home'>Home<a/></li>|
                <li><a href='index.php?title=about'>About Us</a></li>|
                <li><a href='index.php?title=gallery'>Gallery</a></li>|
                <li><a href='index.php?title=contact'>Contact</a></li>
             </ul>
          </div>
       </div>
    
    </div>
    See? You have a main template and subtemplates. You can even use templates for things like select boxes, forms, radio buttons etc. As long as its all put into the *main* template you'll only need to design one main template to hold your content no matter how many pages you have.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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