""
Documentation daCode : daCode webmaster's guide
Chapitre 5. Customization

 
 

Writing a theme

 

Template basics

The basic principle of templates is to separate the content and its formating, on one side, and the logic of the program on the other side. Thus they enable a webmaster to keep his/her site coherent and customize the look and feel whithout changing HTML or PHP code.

 

Writing a template

Templates mix HTML code, comment (lines beginnig with a hash sign « # ») and PHP instructions executed by daCode. They have the form: <!-- daCode: expression --> where « expression » is a PHP expression which returns the text to be substituted to the line. These instructions must be on one line.


    <!-- daCode: $html->header('Exemple') -->
      <table border="0" cellpadding="3" cellspacing="3" width="100%">
      <tr><td valign="top" width="100" rowspan="2">
      <!-- daCode: $sidebox->dacode() -->
      &lt;/td&gt;<td valign="top" width="80%">
      <!-- daCode: $news->show_news(10,$section,$topic,1,1,$news_id) -->
      &lt;/td&gt;
      &lt;/table&gt;
      <!-- daCode: $html->footer() -->
      
   
The first line, for exemlpe, calls the header function, which is defined in the file src/phplip/themes/<theme>/html.php3. This file is called by the Html class, defined in src/phplib/html.php3. header() takes one argument, the title of the page.

 

Using templates

 

We will base this exemple on the preceding one, which we will name "test.tmpl", and we will call it in our page test.php3. We will get the inspiration to create this page from src/htdocs/poll/index.php3 :


      <?
        //  Heading common to all daCode scripts
        $topdir = '..';
        require $topdir."/dacode.php3";
        
        //  Class instances used in test.tmpl
        $html = LoadClass('Html');
        $sidebox = LoadClass('Sidebox');
        $news = LoadClass('News');
        
        //  Create the page
        $html->parsetemplate('test.tmpl');
        ?>
        
        
     
You have to define all the variables which appear in the template. Thus, in ths exemple, the variables $topic and $news_id will be empty. You also have to ensure that all variables are declcared global in the function parsetemplate in the file phplib/html.php3.

 

Create your own static pages

Just copy the file basic.tmpl in the linuxfr theme and adapt it. See the exemple below.


      <!-- daCode: $html->header($title) -->
        <table align="center" width="80%" border="0">
        <tr>
        <td class="bodytext">
        <!-- daCode: $text -->
        &lt;/td&gt;
        &lt;/tr&gt;
        &lt;/table&gt;
        <!-- daCode: $html->footer() -->
        
     


To call it, just do as swe said above -- let's assume the file is call static.tmpl--; but this time, define the values of $text and $title :


      <?
        $topdir = '.';
        require $topdir."/dacode.php3";
        
        $html = LoadClass('Html');
        $sidebox = LoadClass('Sidebox');
        $title="My sooo great page ";
        $text ="My text, with \ before each 
        double quote ";
        $html->parsetemplate('static.tmpl');
        ?>
               
     


 

Creating a new theme

 

Copying an existing theme, and personalizing templates

With all the informations from the preceding section, you can feel it's really easy to create a new theme. Templates are in the directory phplib/themes/<name_of_th_theme>. If you want ot create a "print" theme, begin by copying an existing theme, for exemple daweb : cp -R phplib/themes/daweb phplib/themes/print then modify the *.tmpl files to change the layout.

 

Customizing your theme: styles and images

Once you positionned your boxes with the templates, modify phplib/themes/print/html.php3, which defines the header, footer, and other documetn properties, such as styles or images. To customize:

  • the stylesheets: put the new stylesheet inhtdocs/themes/print/. The styles called (attribute class="") are to be modified directly in html.php3;

  • logos and images: those are called by $this->session->imgurl('image') where image is the name of a png file. daCode will seach it in htdocs/themes/print/images/ first, and then in htdocs/images. The first place is strongly recommended if you want to create an archive for your theme. See section la section intitulée Sharing your themes .

  • Topics images: you sure want to modifiy the background of existing images ou create your own. For the same reasons as above, place them in htdocs/themes/print/images/section. Then use the administration interface ("Topics management") to create new topics.



 

Making your new theme available

In the end, you have to modify the file config.php3 to add this new theme: $this->listofthemes = array('linuxfr','slashdot', 'daweb', 'print'); And if you wish to make it the default for your site: $this->dft_prefs = array ("theme" => 3 ); Where 3 is the position of the theme in the list defined above (numbered from 0 to n)