Author Topic: Using differnet Templates in one PHP-source  (Read 5151 times)

0 Members and 1 Guest are viewing this topic.

Offline StefanD

  • Newbie
  • *
  • Posts: 4
Using differnet Templates in one PHP-source
on: Tue, 17. April 2007 - 20:31:21
Here is an example where I use different template-sources in one PHP-source.
The template-source can be passed by a GET-Parameter called template.

Example 1: With normal/default template-source
Example 2: With another template-source

PHP-Source:
Code: [Select]
<?php
   
if(isset($_GET[template]))
   {
      
$template tmpl/ $_GET[template];
   }
   else
   {
      
$template tmpl/default.htm;
   }

   
// if ordered then show php/html source
   
if (php == $_GET[showsource])
   {
      
show_source($_SERVER[SCRIPT_FILENAME]);
      exit;
   }
   elseif (
html == $_GET[showsource])
   {
      
show_source(dirname(__FILE__) . $template);
      exit;
   }

   require_once 
vlib/vlibTemplate.php;

   
$tmpl = new vlibTemplate($template);

   
$array_ergebnisse = array(
      array(
platz  => 1
         
mannschaft   => Telekom Baskets Bonn,
         
punkte =>  4:0),
      array(
platz  => 2
         
mannschaft   => ALBA BERLIN,
         
punkte =>  2:2),
      array(
platz  => 3
         
mannschaft   =>  Bayer Giants Leverkusen,
         
punkte =>  0:4),
   );

   
$tmpl->setloop(ergebnisse$array_ergebnisse);
   
$tmpl->pparse();
?>

Template 1:
Code: [Select]
<html>
   <head>
      <title>Tabelle - Detailinformationen</title>
   </head>
   <body>
      <a href="vlib_variable_template.php?template=kurztabelle.htm">show short result</a>
      <table frame="1" border="1">
         <tr>
            <th align="left">Platz</th>
            <th align="left">Mannschaft</th>
            <th align="left">Punkte</th>
         </tr>
         <tmpl_loop name=ergebnisse>
         <tr>
            <td align="left"><b>{tmpl_var name=platz}</b></td>
            <td align="left">{tmpl_var name=mannschaft}</td>
            <td align="left">{tmpl_var name=punkte}</td>
         </tr>
         </tmpl_loop>
      </table>
   <p>
      <a href="vlib_variable_template.php?template=default.htm&showsource=php">show PHP code</a> |
      <a href="vlib_variable_template.php?template=default.htm&showsource=html">show template (HTML code)</a>
   </p>
   </body>
</html>

Template 2:
Code: [Select]
<html>
   <head>
      <title>Kurztabelle - Detailinformationen</title>
   </head>
   <body>
      <a href="vlib_variable_template.php?template=default.htm">show standard result</a>
      <table frame="1">
         <tmpl_loop name=ergebnisse>
         <tr>
            <td align="left">{tmpl_var name=platz}.</td>
            <td align="left">{tmpl_var name=mannschaft}</td>
         </tr>
         </tmpl_loop>
      </table>
   </body>
   <p>
      <a href="vlib_variable_template.php?template=kurztabelle.htm&showsource=php">show PHP code</a> |
      <a href="vlib_variable_template.php?template=kurztabelle.htm&showsource=html">show template (HTML code)</a>
   </p>
</html>
Last Edit: Wed, 18. April 2007 - 14:28:14 by ClausVB

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
Re: Using differnet Templates in one PHP-source
Reply #1 on: Wed, 18. April 2007 - 11:03:59
Thank you very much, Stefan.

Great work!

Best regards,
Claus