Template Site : Creating the Template

Step 1 when creating a template based website with Kohana is to create the template.

By default Kohana assumes that the template file is called *template.php* and is located in the views folder.

  /home/kerkness/kohana/application/views/demo/template.php

Your template file should contain the full headers and footers for your web site and echo PHP variables where dynamic content will be inserted by your controller(s). The following very basic template contains the following dynamic content.

  • title (string) - This is the page title
  • scripts (array) - An array of Javascripts required by the page
  • styles (array) - An array of CSS style sheets required by the template
  • content (string) - This is the content of the page

Click here for the source file

  <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
  <head profile="http://gmpg.org/xfn/11">
      <title><?php echo $title ?></title>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  
      <?php foreach ($styles as $file => $type) echo HTML::style($file, array('media' => $type)), "\n" ?>
      <?php foreach ($scripts as $file) echo HTML::script($file), "\n" ?>
  
  </head>
  <body>
    <?php echo $content ?>
  </body>
  </html>

Your template can be as complex or as minimal as you like with as many dynamic elements as necessary.

NEXT : Extending the Template Controller

template-site/create_the_template.txt · Last modified: 2009/10/30 06:06 by jerph